[英]http login to router using python and requests module getting exception
当我尝试登录路由器时,可以正常工作,但是如果密码或用户名错误,则会出现异常。 如何处理此异常?
from requests.auth import HTTPBasicAuth
import requests
def hts():
url = 'http://192.168.1.1/'
name = 'username'
passw = 'password'
auth = HTTPBasicAuth(name,passw)
r = requests.get(url, auth=auth)
try:
if r:
print(r.text)
else:
print("not found")
except requests.exceptions.ContentDecodingError as e:
print('wrong password')
hts()
这是错误
raise ContentDecodingError(e)
requests.exceptions.ContentDecodingError: ('Received response with content-encoding:
gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect
header check',))
try:
r = requests.get(url, auth=auth)
except requests.exceptions.ContentDecodingError as e: # handling the ContentDecoding exception
print('wrong password')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.