my_python.py
import urllib2
filedata = urllib2.urlopen('D:/python/uploadRM/app/file/myfile.pdf') #from local directory not url
datatowrite = filedata.read()
答案 0 :(得分:1)
与open()一起使用以从计算机读取文件
with open("D:/python/uploadRM/app/file/myfile.pdf") as myFile:
#rest of your code
答案 1 :(得分:1)
不确定为什么要使用urlopen()
打开本地文件,但是可以尝试使用file://
HTTP方案:
import urllib2
filedata = urllib2.urlopen('file:///D:/python/uploadRM/app/file/myfile.pdf')
datatowrite = filedata.read()
通常最好使用open()
将其作为普通文件打开:
with open('D:/python/uploadRM/app/file/myfile.pdf') as f:
datatowrite = f.read()