简体   繁体   English

401 响应 Python 请求

[英]401 response with Python requests

I'am using library "requests" for get image from url (' http://any_login:any_password@10.10.9.2/ISAPI/Streaming/channels/101/picture?snapShotImageType=JPEG '), but response error with code 401. Thats url from my rtsp camera.我正在使用库“请求”从 url (' http://any_login:any_password@10.10.9.2/ISAPI/Streaming/channels/101/picture?snapShotImageType=JPEG ') 获取图像,但响应错误代码为 401。那是我的 rtsp 相机的 url。

I try using 'HTTPBasicAuth', 'HTTPDigestAuth' and 'HTTPProxyAuth'.我尝试使用“HTTPBasicAuth”、“HTTPDigestAuth”和“HTTPProxyAuth”。 But it's not working.但它不起作用。

import requests
from requests.auth import HTTPBasicAuth

url = "http://any_login:any_password@10.10.9.2/ISAPI/Streaming/channels/101/picture?snapShotImageType=JPEG"
response = requests.get(url, auth=requests.auth.HTTPBasicAuth("any_login", "any_password"))

if response.status_code == 200:
    with open("sample.jpg", 'wb') as f:
        f.write(response.content)

I expected the output of image file from rtsp flow, but I got error code 401.我预计 rtsp 流中的图像文件为 output,但我收到错误代码 401。

Given your username I suspect your password may contain non-ASCII characters.根据您的用户名,我怀疑您的密码可能包含非 ASCII 字符。 I had a similar issue with a password containing diacritics.我在使用包含变音符号的密码时遇到了类似的问题。

This worked :这有效:

curl -u user:pwd --basic https://example.org

This (and variations) throwed 401 Unauthorized :这(和变体)抛出401 Unauthorized

import requests
requests.get("https://example.org", auth=requests.auth.HTTPBasicAuth("user","pwd"))

Changing the password to ASCII only characters solved the issue.将密码更改为仅 ASCII 字符解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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