Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Body data is not a string or bytes class. #25

Open
bitjerry opened this issue Jan 29, 2024 · 0 comments
Open

Body data is not a string or bytes class. #25

bitjerry opened this issue Jan 29, 2024 · 0 comments

Comments

@bitjerry
Copy link

The upload failed when the data was uploaded, but this operation was available in requests

data = open("test.wav", "rb")
# tls_config.ja3 = requests.tls_config.JA3Random(tls_config.ja3)
# resp = await requests.async_post(url=url, data=data, headers=headers, params=params, verify=False,
#                                  tls_config=tls_config)
resp = requests.post(url=url, data=data, headers=headers, params=params, verify=False)
print(resp.text)

the error

Traceback (most recent call last):
File ".venv\Lib\site-packages\requests_go\adapters.py", line 473, in send
resp = conn.send(tls_request)
^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests_go\pool.py", line 45, in send
response = tls_handler.send(options)
^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests_go\request.py", line 25, in send
response = self._session.request(**options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests_go\tls_client\request.py", line 78, in request
raise TLSClientExeption("Body data is not a string or bytes class.")
requests_go.tls_client.exceptions.TLSClientExeption: Body data is not a string or bytes class.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "\SpeechRecognitionAWS\deepl.py", line 45, in
asyncio.run(deepl())
File "C:\null\python\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\null\python\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\null\python\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "\SpeechRecognitionAWS\deepl.py", line 40, in deepl
resp = requests.post(url=url, data=data, headers=headers, params=params, verify=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests_go\api.py", line 116, in post
return request("post", url, data=data, json=json, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests_go\api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests_go\sessions.py", line 230, in request
resp = self.send(prep, **send_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests\sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests_go\adapters.py", line 476, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: Body data is not a string or bytes class.

How should I use bytes on the request body?

data = open("test.wav", "rb").read()
# tls_config.ja3 = requests.tls_config.JA3Random(tls_config.ja3)
# resp = await requests.async_post(url=url, data=data, headers=headers, params=params, verify=False,
#                                  tls_config=tls_config)
resp = requests.post(url=url, data=data, headers=headers, params=params, verify=False)
print(resp.text)

Traceback (most recent call last):
File "\SpeechRecognitionAWS\deepl.py", line 45, in
asyncio.run(deepl())
File "C:\null\python\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\null\python\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\null\python\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "\SpeechRecognitionAWS\deepl.py", line 40, in deepl
resp = requests.post(url=url, data=data, headers=headers, params=params, verify=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests_go\api.py", line 116, in post
return request("post", url, data=data, json=json, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests_go\api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests_go\sessions.py", line 230, in request
resp = self.send(prep, **send_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests\sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests_go\adapters.py", line 473, in send
resp = conn.send(tls_request)
^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests_go\pool.py", line 45, in send
response = tls_handler.send(options)
^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests_go\request.py", line 25, in send
response = self._session.request(**options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv\Lib\site-packages\requests_go\tls_client\request.py", line 76, in request
request_params["Body"] = body.decode()
^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant