![](/img/trans.png)
[英]Python requests: upload a file and subsequently parse data from a redirection
[英]Upload a file and handle redirection [PYTHON]
我需要向站点https://zxing.org/w/decode.jspx提交图像,并阅读结果页面: https://zxing.org/w/decode 。
我试过这个,但它不起作用:
def decode_qrcode(path):
s = requests.Session()
url = "https://zxing.org/w/decode.jspx"
files = {'file': open(path, 'rb')}
s.post(url, files=files)
return s.get("https://zxing.org/w/decode").text
我知道有一些库可以读取 QR 码,但我没有找到任何适用于我使用的那种 QR 码的库(它们可能不支持错误率)。
发出POST
请求时必须使用allow_redirects
参数
import requests
def decode_qrcode(path):
s = requests.Session()
url = "https://zxing.org/w/decode.jspx"
files = {'file': open(path, 'rb')}
s.post(url, files=files, allow_redirects = True)
return s.get("https://zxing.org/w/decode").text
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.