所以我正在尝试读取 .bak 文件,从谷歌搜索来看,似乎 rebase 是可行的方法,但是我不断收到回溯错误
回溯(最近一次调用最后一次): 文件“C:filepath”,第 1 行,位于 从海报.编码导入multipart_encode 文件“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(值) ^ 语法错误:语法无效
重新设置数据代码:
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”替换了原来的文件路径
看来
poster
模块正在尝试使用 Python 2 类型 print "x"
语法而不是 Python 3 print("x")
语法。
您可能尝试使用错误版本的
poster
。有一个名为 poster3
的模块,也许可以尝试一下。
我更改了请求,因为我使用的是 python 3
import requests
response = requests.post('https://www.rebasedata.com/api/v1/convert', files={'files[]': open('PDVUPDATES.FDB','rb')})
# Write the response to /tmp/output.zip
with open('/tmp/outpuat.zip', 'wb') as local_file:
b = bytes(response.text, 'utf-8')
local_file.write(response.content)
print('Conversion result successfully written to /tmp/output.zip!')