簡體   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