FlorianREGAZ / Python-Tls-Client

Advanced HTTP Library
MIT License
679 stars 135 forks source link

can't send data #12

Closed TrixTM closed 1 year ago

TrixTM commented 1 year ago

I can't send data like this: r= session.post(f"https://example.com/", headers={....}, data=data} Only json=json works, but i need it to work with data=data too.

ghost commented 1 year ago

same here, trying to post bytes as data doesn't work:

Traceback (most recent call last):
[...]
  File [redacted]
    r = session.post(
        ^^^^^^^^^^^^^
  File "[redacted]/.venv/lib/python3.11/site-packages/tls_client/sessions.py", line 369, in post
    return self.execute_request(method="POST", url=url, data=data, json=json, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[redacted]/.venv/lib/python3.11/site-packages/tls_client/sessions.py", line 315, in execute_request
    response = request(dumps(request_payload).encode('utf-8'))
                       ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alexia/.local/share/pyenv/versions/3.11.0/lib/python3.11/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alexia/.local/share/pyenv/versions/3.11.0/lib/python3.11/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alexia/.local/share/pyenv/versions/3.11.0/lib/python3.11/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "/home/alexia/.local/share/pyenv/versions/3.11.0/lib/python3.11/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes is not JSON serializable
TrixTM commented 1 year ago

@FlorianREGAZ it would be nice if you can add the option to send data, not just json

FlorianREGAZ commented 1 year ago

Could you send me a full example so I can run your code please

ghost commented 1 year ago
import tls_client

session = tls_client.Session(client_identifier="chrome_108")

res = session.post(
        url="https://httpbin.org/anything",
        data=b"\x01\x02\x03\x04",
).json()
print(res)
kekeds commented 1 year ago

SKID CANT CODE