当前位置:网站首页>Error reporting solution - io UnsupportedOperation: can‘t do nonzero end-relative seeks
Error reporting solution - io UnsupportedOperation: can‘t do nonzero end-relative seeks
2022-07-06 11:07:00 【zkkkkkkkkkkkkk】
Catalog
Four 、seek Function introduction
One 、 Error code
with open(pdfpath,"r") as fp:
Two 、 Error message
PdfReadWarning: PdfFileReader stream/file object is not in binary mode. It may not be read correctly. [pdf.py:1143]
Traceback (most recent call last):
File "D:/Gitlab/my_world/recognize_img/pdf_to_img.py", line 36, in <module>
jiemi('D:\\Gitlab\\my_world\\recognize_img\\demo_img\\ The frameless table cannot be edited .pdf')
File "D:/Gitlab/my_world/recognize_img/pdf_to_img.py", line 9, in jiemi
pdfFile = PyPDF4.pdf.PdfFileReader(fp)
File "C:\Users\dell\Anaconda3\lib\site-packages\PyPDF4\pdf.py", line 1148, in __init__
self.read(stream)
File "C:\Users\dell\Anaconda3\lib\site-packages\PyPDF4\pdf.py", line 1754, in read
stream.seek(-1, 2)
io.UnsupportedOperation: can't do nonzero end-relative seeks
Process finished with exit code 1
Two 、 Solution
When reporting a mistake seek() An exception thrown by a function . resolvent : If you use open() Function to open a file ( For example, I use open() Function to open pdf), You have to use r+b How to read .
def read_pdf(file_path):
with open(pdfpath,"rb") as fp:
pdfFile = PyPDF4.pdf.PdfFileReader(fp)
print(pdf.pages)
fp.close()
if __name__ == '__main__':
file_path = 'D:\\Gitlab\\my_world\\recognize_img\\demo_img\\ The frameless table cannot be edited .pdf'
read_pdf(file_path)Four 、seek Function introduction
This error is caused by seek() An exception thrown by a function .seek() Functions are common in reading files , It has the function of pointer . Usually in the process of reading documents , The pointer will then move to record the current read position .seek() Function can also move the pointer to the specified position .
seek Use of functions
fp.seek(0, 0) # first 0 Represents the offset , the second 0 Represents where to start the offset (0: From the beginning of the file ,1: From the current position ,2: From the end of the file .)
# Open file
with open("runoob.txt", "rw+") as fp:
line = fp.readline()
print(" Reading data :",line)
# Reset the file read pointer to the beginning
fp.seek(0, 0) # first 0 Represents the offset , the second 0 Represents where to start the offset (0: From the beginning of the file ,1: From the current position ,2: From the end of the file .)
line = fp.readline()
print(" Read data after reset :",line)
# Close file
fp.close()边栏推荐
- Introduction to the easy copy module
- Kubernetes - problems and Solutions
- Ansible practical Series III_ Task common commands
- API learning of OpenGL (2003) gl_ TEXTURE_ WRAP_ S GL_ TEXTURE_ WRAP_ T
- JDBC原理
- 虚拟机Ping通主机,主机Ping不通虚拟机
- Remember a company interview question: merge ordered arrays
- MySQL18-MySQL8其它新特性
- 一键提取pdf中的表格
- 导入 SQL 时出现 Invalid default value for ‘create_time‘ 报错解决方法
猜你喜欢

CSDN问答标签技能树(一) —— 基本框架的构建

基于apache-jena的知识问答

Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘

API learning of OpenGL (2002) smooth flat of glsl

Valentine's Day is coming, are you still worried about eating dog food? Teach you to make a confession wall hand in hand. Express your love to the person you want

引入了junit为什么还是用不了@Test注解

CSDN博文摘要(一) —— 一个简单的初版实现
![[ahoi2009]chess Chinese chess - combination number optimization shape pressure DP](/img/7d/8cbbd2f328a10808319458a96fa5ec.jpg)
[ahoi2009]chess Chinese chess - combination number optimization shape pressure DP

C language advanced pointer Full Version (array pointer, pointer array discrimination, function pointer)

Win10: how to modify the priority of dual network cards?
随机推荐
JDBC principle
Data dictionary in C #
Breadth first search rotten orange
Windows下安装MongDB教程、Redis教程
A trip to Macao - > see the world from a non line city to Macao
SSM整合笔记通俗易懂版
MySQL master-slave replication, read-write separation
Use dapr to shorten software development cycle and improve production efficiency
Swagger、Yapi接口管理服务_SE
@Controller, @service, @repository, @component differences
Solution: log4j:warn please initialize the log4j system properly
Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘
Ansible实战系列二 _ Playbook入门
Deoldify项目问题——OMP:Error#15:Initializing libiomp5md.dll,but found libiomp5md.dll already initialized.
API learning of OpenGL (2003) gl_ TEXTURE_ WRAP_ S GL_ TEXTURE_ WRAP_ T
Invalid global search in idea/pychar, etc. (win10)
[recommended by bloggers] C WinForm regularly sends email (with source code)
Win10: how to modify the priority of dual network cards?
01项目需求分析 (点餐系统)
Postman uses scripts to modify the values of environment variables