I am using OAuth authentication to fetch the Access token using python. Below is my code snippet
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
client = BackendApplicationClient(client_id=OAUTH_CLIENT_ID)
oauth = OAuth2Session(client=client)
token_details = oauth.fetch_token(token_url=OAUTH_TOKEN_URL, client_id=OAUTH_CLIENT_ID, client_secret=OAUTH_CLIENT_SECRET)
When I try to fetch the token I am facing the below error.
/home/dinesh/.pyenv/versions/yms-outbound-shipment/bin/python3.9 /home/dinesh/workspace/yms-outbound-shipment/yms_outbound_shipment/service/authentication.py
Traceback (most recent call last):
File "/home/dinesh/.pyenv/versions/yms-outbound-shipment/lib/python3.9/site-packages/urllib3/response.py", line 748, in _update_chunk_length
self.chunk_left = int(line, 16)
ValueError: invalid literal for int() with base 16: b''
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/dinesh/.pyenv/versions/yms-outbound-shipment/lib/python3.9/site-packages/urllib3/response.py", line 443, in _error_catcher
yield
File "/home/dinesh/.pyenv/versions/yms-outbound-shipment/lib/python3.9/site-packages/urllib3/response.py", line 815, in read_chunked
self._update_chunk_length()
File "/home/dinesh/.pyenv/versions/yms-outbound-shipment/lib/python3.9/site-packages/urllib3/response.py", line 752, in _update_chunk_length
raise InvalidChunkLength(self, line)
urllib3.exceptions.InvalidChunkLength: InvalidChunkLength(got length b'', 0 bytes read)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/dinesh/.pyenv/versions/yms-outbound-shipment/lib/python3.9/site-packages/requests/models.py", line 816, in generate
yield from self.raw.stream(chunk_size, decode_content=True)
File "/home/dinesh/.pyenv/versions/yms-outbound-shipment/lib/python3.9/site-packages/urllib3/response.py", line 623, in stream
for line in self.read_chunked(amt, decode_content=decode_content):
File "/home/dinesh/.pyenv/versions/yms-outbound-shipment/lib/python3.9/site-packages/urllib3/response.py", line 844, in read_chunked
self._original_response.close()
File "/home/dinesh/.pyenv/versions/3.9.5/lib/python3.9/contextlib.py", line 135, in __exit__
self.gen.throw(type, value, traceback)
File "/home/dinesh/.pyenv/versions/yms-outbound-shipment/lib/python3.9/site-packages/urllib3/response.py", line 460, in _error_catcher
raise ProtocolError("Connection broken: %r" % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/dinesh/workspace/yms-outbound-shipment/yms_outbound_shipment/service/authentication.py", line 76, in <module>
print(authenticate.get_oauth_access_token('colgate'))
File "/home/dinesh/workspace/yms-outbound-shipment/yms_outbound_shipment/service/authentication.py", line 27, in get_oauth_access_token
token_details = oauth.fetch_token(token_url=settings.OAUTH_TOKEN_URL, client_id=settings.OAUTH_CLIENT_ID,
File "/home/dinesh/.pyenv/versions/yms-outbound-shipment/lib/python3.9/site-packages/requests_oauthlib/oauth2_session.py", line 341, in fetch_token
r = self.request(
File "/home/dinesh/.pyenv/versions/yms-outbound-shipment/lib/python3.9/site-packages/requests_oauthlib/oauth2_session.py", line 521, in request
return super(OAuth2Session, self).request(
File "/home/dinesh/.pyenv/versions/yms-outbound-shipment/lib/python3.9/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/home/dinesh/.pyenv/versions/yms-outbound-shipment/lib/python3.9/site-packages/requests/sessions.py", line 745, in send
r.content
File "/home/dinesh/.pyenv/versions/yms-outbound-shipment/lib/python3.9/site-packages/requests/models.py", line 899, in content
self._content = b"".join(self.iter_content(CONTENT_CHUNK_SIZE)) or b""
File "/home/dinesh/.pyenv/versions/yms-outbound-shipment/lib/python3.9/site-packages/requests/models.py", line 818, in generate
raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))
Process finished with exit code 1
Versions:
python == 3.9.5
requests == 2.28.1
requests-oauthlib == 1.3.1
oauthlib == 3.2.1
urllib3 == 1.26.12
Can someone help me identify the issue and help me solve?