使用 httpx 的身份验证问题
Auth Issue using httpx
有效回复:
import requests
with requests.Session() as req:
req.auth = authdata
req.headers.update({
'x-amz-access-token': access
})
r = req.get(
'https://sellingpartnerapi-na.amazon.com/orders/v0/orders/', params=params)
print(r)
但是使用 httpx
得到:
import httpx
async with httpx.AsyncClient(timeout=None) as client:
client.auth = authdata
client.headers.update({
'x-amz-access-token': access
})
r = await client.get('https://sellingpartnerapi-na.amazon.com/orders/v0/orders/', params=params)
print(r)
完整追溯:
Traceback (most recent call last):
File "c:\Users\AmericaN\Desktop\Lab\code.py", line 60, in <module>
trio.run(main)
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\trio\_core\_run.py", line 1932, in run
raise runner.main_task_outcome.error
File "c:\Users\AmericaN\Desktop\Lab\code.py", line 56, in main
await get_orders(authdata, await get_token())
File "c:\Users\AmericaN\Desktop\Lab\code.py", line 49, in get_orders
r = await client.get('https://sellingpartnerapi-na.amazon.com/orders/v0/orders/', params=params)
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_client.py", line 1539, in get
return await self.request(
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_client.py", line 1361, in request
response = await self.send(
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_client.py", line 1396, in send
response = await self._send_handling_auth(
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_client.py", line 1428, in _send_handling_auth
request = await auth_flow.__anext__()
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_auth.py", line 92, in async_auth_flow
request = next(flow)
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_auth.py", line 115, in auth_flow
yield self._func(request)
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\requests_auth_aws_sigv4\__init__.py", line 109, in __call__
p = urlparse(r.url)
File "C:\Program Files\Python39\lib\urllib\parse.py", line 389, in urlparse
url, scheme, _coerce_result = _coerce_args(url, scheme)
File "C:\Program Files\Python39\lib\urllib\parse.py", line 125, in _coerce_args
return _decode_args(args) + (_encode_result,)
File "C:\Program Files\Python39\lib\urllib\parse.py", line 109, in _decode_args
return tuple(x.decode(encoding, errors) if x else '' for x in args)
File "C:\Program Files\Python39\lib\urllib\parse.py", line 109, in <genexpr>
return tuple(x.decode(encoding, errors) if x else '' for x in args)
AttributeError: 'URL' object has no attribute 'decode'
使用以下方法解决:httpx-auth
有效回复:
import requests
with requests.Session() as req:
req.auth = authdata
req.headers.update({
'x-amz-access-token': access
})
r = req.get(
'https://sellingpartnerapi-na.amazon.com/orders/v0/orders/', params=params)
print(r)
但是使用 httpx
得到:
import httpx
async with httpx.AsyncClient(timeout=None) as client:
client.auth = authdata
client.headers.update({
'x-amz-access-token': access
})
r = await client.get('https://sellingpartnerapi-na.amazon.com/orders/v0/orders/', params=params)
print(r)
完整追溯:
Traceback (most recent call last):
File "c:\Users\AmericaN\Desktop\Lab\code.py", line 60, in <module>
trio.run(main)
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\trio\_core\_run.py", line 1932, in run
raise runner.main_task_outcome.error
File "c:\Users\AmericaN\Desktop\Lab\code.py", line 56, in main
await get_orders(authdata, await get_token())
File "c:\Users\AmericaN\Desktop\Lab\code.py", line 49, in get_orders
r = await client.get('https://sellingpartnerapi-na.amazon.com/orders/v0/orders/', params=params)
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_client.py", line 1539, in get
return await self.request(
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_client.py", line 1361, in request
response = await self.send(
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_client.py", line 1396, in send
response = await self._send_handling_auth(
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_client.py", line 1428, in _send_handling_auth
request = await auth_flow.__anext__()
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_auth.py", line 92, in async_auth_flow
request = next(flow)
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_auth.py", line 115, in auth_flow
yield self._func(request)
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\requests_auth_aws_sigv4\__init__.py", line 109, in __call__
p = urlparse(r.url)
File "C:\Program Files\Python39\lib\urllib\parse.py", line 389, in urlparse
url, scheme, _coerce_result = _coerce_args(url, scheme)
File "C:\Program Files\Python39\lib\urllib\parse.py", line 125, in _coerce_args
return _decode_args(args) + (_encode_result,)
File "C:\Program Files\Python39\lib\urllib\parse.py", line 109, in _decode_args
return tuple(x.decode(encoding, errors) if x else '' for x in args)
File "C:\Program Files\Python39\lib\urllib\parse.py", line 109, in <genexpr>
return tuple(x.decode(encoding, errors) if x else '' for x in args)
AttributeError: 'URL' object has no attribute 'decode'
使用以下方法解决:httpx-auth