401 response with Python requests

I'am using library "requests" for get image from url ('http://any_login:[email protected]/ISAPI/Streaming/channels/101/picture?snapShotImageType=JPEG'), but response error with code 401. Thats url from my rtsp camera.

I try using 'HTTPBasicAuth', 'HTTPDigestAuth' and 'HTTPProxyAuth'. But it's not working.

import requests
from requests.auth import HTTPBasicAuth

url = "http://any_login:[email protected]/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.

Upvotes: 2

Views: 879

Answers (1)

Skippy le Grand Gourou
Skippy le Grand Gourou

Reputation: 7724

Given your username I suspect your password may contain non-ASCII characters. 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 :

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

Changing the password to ASCII only characters solved the issue.

Upvotes: 1

Related Questions