Erron when run python code
gaetan1903 opened this issue · 4 comments
gaetan1903 commented
Traceback (most recent call last):
File "/home/hck1903/Bureau/test.py", line 20, in <module>
r = s.post(
File "/usr/lib/python3.9/site-packages/requests/sessions.py", line 590, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/usr/lib/python3.9/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3.9/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.9/site-packages/urllib3/connection.py", line 234, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "/usr/lib/python3.9/http/client.py", line 1257, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.9/http/client.py", line 1298, in _send_request
self.putheader(hdr, value)
File "/usr/lib/python3.9/site-packages/urllib3/connection.py", line 219, in putheader
_HTTPConnection.putheader(self, header, *values)
File "/usr/lib/python3.9/http/client.py", line 1225, in putheader
raise ValueError('Invalid header name %r' % (header,))
ValueError: Invalid header name b':method'
Try: Latest version in pypi : pip install har2requests
and latest git version : pip install git+https://github.com/louisabraham/har2requests.git
louisabraham commented
I would need to see the generated python code, even if it is obfuscated to hide urls.
gaetan1903 commented
import requests
s = requests.Session()
s.headers.update(
{
":method": "POST",
":scheme": "https",
"accept": "application/json, text/javascript, */*; q=0.01",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36",
"sec-gpc": "1",
"origin": "https://www.reverso.net",
"sec-fetch-mode": "cors",
"sec-fetch-dest": "empty",
"accept-encoding": "gzip, deflate, br",
"accept-language": "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7",
}
)
r = s.post(
"https://www.reverso.net/orthographe/correcteur-francais/ServerInterface.asmx/GetLgDetect",
headers={
":authority": "www.reverso.net",
":path": "/orthographe/correcteur-francais/ServerInterface.asmx/GetLgDetect",
"content-length": "28",
"x-requested-with": "XMLHttpRequest",
"content-type": "application/json; charset=UTF-8",
"sec-fetch-site": "same-origin",
"referer": "https://www.reverso.net/orthographe/correcteur-francais/",
"cookie": "ASP.NET_SessionId=avui0ngkqys2iiloiuom4csd; RVRSONODEID=node1; reverso.net.LanguageInterface=fr; reverso.net.newpv=0; didomi_token=eyJ1c2VyX2lkIjoiMTdiYzQ3YTAtNTYyOS02MjM1LTllYzEtNTkyM2I4NmExOWQzIiwiY3JlYXRlZCI6IjIwMjEtMDktMDhUMDg6MTU6MzYuNDcxWiIsInVwZGF0ZWQiOiIyMDIxLTA5LTA4VDA4OjE1OjM2LjQ3MVoiLCJ2ZXJzaW9uIjpudWxsfQ==; experiment_speller_da2q2W32a=0",
},
data="{'text': 'Je suis un test '}",
)
# {
# "d": {
# "__type": "Speller.BusinessObjects.LanguageDetectionResult",
# "Language": null,
# "Succeeded": true
# }
# }
s.headers.update(
{
":authority": "orthographe.reverso.net",
":path": "/api/v1/Spelling",
"sec-fetch-site": "same-site",
"referer": "https://www.reverso.net/",
}
)
r = s.post(
"https://orthographe.reverso.net/api/v1/Spelling",
headers={"content-length": "219", "content-type": "application/json"},
json={
"language": "fra",
"text": "Je suis un test ",
"autoReplace": True,
"interfaceLanguage": "fr",
"locale": "Indifferent",
"origin": "interactive",
"generateSynonyms": False,
"generateRecommendations": False,
"getCorrectionDetails": True,
},
)
# {
# "id": "338947e0-2c56-4974-9d91-855174e8b1d7",
# "language": "fra",
# "text": "Je suis un test ",
# "engine": "Cordial",
# "truncated": false,
# "timeTaken": 1,
# "corrections": [],
# "sentences": [],
# "autoReplacements": []
# }
s.headers.update({"sec-gpc": None})
r = s.options(
"https://orthographe.reverso.net/api/v1/Spelling",
headers={
":method": "OPTIONS",
"accept": "*/*",
"access-control-request-method": "POST",
"access-control-request-headers": "content-type",
},
)
louisabraham commented
What browser did you use to generate the .har file?
I could ignore the headers that don't fit a certain regex.
louisabraham commented
I could ignore the headers that don't fit a certain regex.
Can you test again? I just did that.