【发布时间】:2022-01-25 22:05:48
【问题描述】:
所以我正在尝试读取一个 .bak 文件,从谷歌上搜索,似乎 rebase 是要走的路,但是我不断收到回溯错误
Traceback(最近一次调用最后一次): 文件“C:filepath”,第 1 行,在 从海报.编码导入多部分编码 文件“C:filepath\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\poster_init_.py”,第 4 行,在 导入海报.streaminghttp 文件“C:filepath\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\poster\streaminghttp.py”,第 58 行 打印“发送:”,repr(值) ^ SyntaxError: 无效语法
重新建立数据代码:
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import urllib2
#Register the streaming http handlers with urllib2
register_openers()
#Use multipart encoding for the input files
datagen, headers = multipart_encode({ 'files[]': open('example.bak', 'rb')})
#Create the request object
request = urllib2.Request('https://www.rebasedata.com/api/v1/convert', datagen, headers)
#Do the request and get the response
#Here the BAK file gets converted to CSV
response = urllib2.urlopen(request)
#Check if an error came back
if response.info().getheader('Content-Type') == 'application/json':
print response.read()
sys.exit(1)
#Write the response to /tmp/output.zip
with open('/tmp/output.zip', 'wb') as local_file:
local_file.write(response.read())
print 'Conversion result successfully written to /tmp/output.zip!'
我如何真正让这个脚本运行?谢谢。 注意我用“filepath”替换了我的原始文件路径
【问题讨论】: