当前位置:网站首页>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()边栏推荐
- frp内网穿透那些事
- Did you forget to register or load this tag 报错解决方法
- Leetcode 461 Hamming distance
- 【博主推荐】SSM框架的后台管理系统(附源码)
- CSDN问答模块标题推荐任务(一) —— 基本框架的搭建
- 虚拟机Ping通主机,主机Ping不通虚拟机
- Data dictionary in C #
- Ansible practical Series II_ Getting started with Playbook
- Yum prompt another app is currently holding the yum lock; waiting for it to exit...
- neo4j安装教程
猜你喜欢

A trip to Macao - > see the world from a non line city to Macao

Django运行报错:Error loading MySQLdb module解决方法
![[recommended by bloggers] asp Net WebService background data API JSON (with source code)](/img/04/c721e6177b578b30cbbf334cb1b6c9.png)
[recommended by bloggers] asp Net WebService background data API JSON (with source code)

Neo4j installation tutorial

Mysql21 user and permission management

Mysql22 logical architecture

Redis的基础使用

Invalid global search in idea/pychar, etc. (win10)

02-项目实战之后台员工信息管理

LeetCode #461 汉明距离
随机推荐
35 is not a stumbling block in the career of programmers
Did you forget to register or load this tag 报错解决方法
Windows cannot start the MySQL service (located on the local computer) error 1067 the process terminated unexpectedly
Solve the problem that XML, YML and properties file configurations cannot be scanned
解决:log4j:WARN Please initialize the log4j system properly.
The virtual machine Ping is connected to the host, and the host Ping is not connected to the virtual machine
Idea import / export settings file
Record a problem of raspberry pie DNS resolution failure
windows无法启动MYSQL服务(位于本地计算机)错误1067进程意外终止
引入了junit为什么还是用不了@Test注解
Django运行报错:Error loading MySQLdb module解决方法
1. Mx6u learning notes (VII): bare metal development (4) -- master frequency and clock configuration
解决扫描不到xml、yml、properties文件配置
Remember the interview algorithm of a company: find the number of times a number appears in an ordered array
[reading notes] rewards efficient and privacy preserving federated deep learning
Attention apply personal understanding to images
虚拟机Ping通主机,主机Ping不通虚拟机
Breadth first search rotten orange
基于apache-jena的知识问答
Ansible实战系列三 _ task常用命令