[英]Upload a file and handle redirection [PYTHON]
I need to submit an image to the site https://zxing.org/w/decode.jspx , and read the result page: https://zxing.org/w/decode .我需要向站点https://zxing.org/w/decode.jspx提交图像,并阅读结果页面: https://zxing.org/w/decode 。
I tried this, but it does not work:我试过这个,但它不起作用:
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
I know that there are librairies to read QR code, but I did not find any that works for the kind of QR codes that I work with (they might have an error rate not supported).我知道有一些库可以读取 QR 码,但我没有找到任何适用于我使用的那种 QR 码的库(它们可能不支持错误率)。
You have to use the allow_redirects
argument when making the POST
request发出
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.