繁体   English   中英

上传文件并处理重定向 [PYTHON]

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM