Closed Thomas-Tsai closed 2 months ago
are you able to reproduce the error in a test with vcr?
I'm not able to reproduce the error, but if I can see the vcr cassette, I can see what the issue is
yes, this is the screencast link https://drive.google.com/file/d/1kzgJaraRU7OrWQLZ3Z3LLx5fqV8uVQvQ/view?usp=sharing
I am also trying to get the latest code from git master branch but got the same result.
get message from self.content in requests/models.py: line 955
b'<?xml version="1.0" encoding="UTF-8"?>\n<Error><Code>InvalidArgument</Code><Message>Unsupported Authorization Type</Message><ArgumentName>Authorization</ArgumentName><ArgumentValue>Basic dGhvbWFzOm9rb2s3NDgw</ArgumentValue><RequestId>DTX5AFE0WJY72Y4Y</RequestId><HostId>0NnwVBihhvipKcl2+KZp9+i5C8DWBya749aAb9QRPnJNJpRgmUV13xXH5eJS0On3THdIJpnhVuU=</HostId></Error>'
and also try to access oauth_consumer.json is fine....
curl https://thegarth.s3.amazonaws.com/oauth_consumer.json
{
"consumer_key": "fc3e99d2-118c-44b8-8ae3-03370dde24c0",
"consumer_secret": "E08WAR897WEy2knn7aFBrvegVAf0AFdWBBF"
}
finally, manually add this json data to OAUTH_CONSUMER(gather/sso.py: 18) then get a successful login and create t 2 files (oauth1_token.json oauth2_token.json )
no idea why requests.get(OAUTH_CONSUMER_URL).json()
can not get the right JSON data but curl works fine with me.
What happens if you manually run these line?
import requests
OAUTH_CONSUMER_URL = "https://thegarth.s3.amazonaws.com/oauth_consumer.json"
requests.get(OAUTH_CONSUMER_URL).json()
The result:
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>>
>>> OAUTH_CONSUMER_URL = "https://thegarth.s3.amazonaws.com/oauth_consumer.json"
>>> requests.get(OAUTH_CONSUMER_URL).json()
Traceback (most recent call last):
File "/home/thomas/newtest/lib/python3.11/site-packages/requests/models.py", line 963, in json
return complexjson.loads(self.content.decode(encoding), **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/thomas/newtest/lib/python3.11/site-packages/requests/models.py", line 971, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
which is run with a clean virtual environment.
(newtest) thomas@debian-lab:~/newtest$ pip list
Package Version
---------- -------
pip 23.0.1
setuptools 66.1.1
(newtest) thomas@debian-lab:~/newtest$ pip install requests
Collecting requests
Using cached requests-2.32.3-py3-none-any.whl (64 kB)
Collecting charset-normalizer<4,>=2
Using cached charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (140 kB)
Collecting idna<4,>=2.5
Using cached idna-3.7-py3-none-any.whl (66 kB)
Collecting urllib3<3,>=1.21.1
Using cached urllib3-2.2.2-py3-none-any.whl (121 kB)
Collecting certifi>=2017.4.17
Using cached certifi-2024.6.2-py3-none-any.whl (164 kB)
Installing collected packages: urllib3, idna, charset-normalizer, certifi, requests
Successfully installed certifi-2024.6.2 charset-normalizer-3.3.2 idna-3.7 requests-2.32.3 urllib3-2.2.2
more tests here:
>>> r=requests.get(OAUTH_CONSUMER_URL)
>>> r.content
b'<?xml version="1.0" encoding="UTF-8"?>\n<Error><Code>InvalidArgument</Code><Message>Unsupported Authorization Type</Message><ArgumentName>Authorization</ArgumentName><ArgumentValue>Basic dGhvbWFzOm9rb2s3NDgw</ArgumentValue><RequestId>9ABBTPSJRQ6EAFPE</RequestId><HostId>7lkaDVbpMP1Nz8i66D3/UhzVgFOqZtZ6Dyc+Y7nu+Ou2KjLXMDAM6/ZieuqULGWU6nmLtxqZxMQ=</HostId></Error>'
>>> r.request.headers
{'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Authorization': 'Basic XXXXXX'}
Why Authorization in headers? try to remove that
>>> req = requests.Request('GET',OAUTH_CONSUMER_URL ,headers={})
>>> prepared = req.prepare()
>>> s = requests.Session()
>>> nr=s.send(prepared)
>>> nr
<Response [200]>
>>> nr.content
b'{\n "consumer_key": "",\n "consumer_secret": "E08WAR897WEy2knn7aFBrvegVAf0AFdWBBF"\n}'
>>>
I believe the root cause is here and I have no idea why requests auto-add auth in this headers.
Basic dGhvbWFzOm9rb2s3NDgw
decodes to thomas:okok7480
. does that seem familiar to you?
sure, I am super familiar with this. It's my secret when I am a student. This is my environmental issue, and thanks for your help!
Hi, I am trying to log in to my Garmin Connect using your sample code, but I got the error message:
the sample code:
ERROR MESSAGE:
The pip list result is:
Running on my debian host machine with kernel Linux debian-lab 6.1.0-21-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.90-1 (2024-05-03) x86_64 GNU/Linux
any idea?