juancarlospaco / faster-than-requests

Faster requests on Python 3
https://gist.github.com/juancarlospaco/37da34ed13a609663f55f4466c4dbc3e
MIT License
1.09k stars 91 forks source link

ERROR IN POST REQUEST WITH JSON BODY #179

Closed caioluccas closed 2 years ago

caioluccas commented 2 years ago

Im trying to do a POST request with json body but its returnig this error: TypeError: Can't convert python obj of type 'list' to string

requests.post(url, user_agent=user_agent, body={"summonerName": nick_to_snipe, "accountId": account_id, "items"[{"inventoryType":"SUMMONER_CUSTOMIZATION","itemId":1,"rpCost": 1300, "quantity":1}]}, http_headers=main_header)
juancarlospaco commented 2 years ago

Body takes string.

caioluccas commented 2 years ago

so how can i post with json, like in requests?

juancarlospaco commented 2 years ago
thing = {"summonerName": nick_to_snipe, "accountId": account_id, "items"[{"inventoryType":"SUMMONER_CUSTOMIZATION","itemId":1,"rpCost": 1300, "quantity":1}]}
json.dumps(thing)
caioluccas commented 2 years ago

now its returning TypeError: Can't convert python obj of type 'dict' to string

juancarlospaco commented 2 years ago

Post the whole code, is hard to understand whats what just by variable names, make like a reduced example. body only takes string.

caioluccas commented 2 years ago
payload = {"summonerName": nick_to_snipe, "accountId": account_id, "items":[{"inventoryType":"SUMMONER_CUSTOMIZATION","itemId":1,"ipCost":13900, "quantity":1}]}
json.dumps(payload) 
buy = requests.post(url, user_agent=user_agent, body=payload, http_headers=main_header)
juancarlospaco commented 2 years ago
payload = {"summonerName": nick_to_snipe, "accountId": account_id, "items":[{"inventoryType":"SUMMONER_CUSTOMIZATION","itemId":1,"ipCost":13900, "quantity":1}]}
payload_string = json.dumps(payload) 
buy = requests.post(url, user_agent=user_agent, body=payload_string, http_headers=main_header)
caioluccas commented 2 years ago

i already tried it, its returning TypeError: Can't convert python obj of type 'list' to string

juancarlospaco commented 2 years ago

Then it is some of the other arguments that is failing. Post the whole code otherwise theres no way to know.

caioluccas commented 2 years ago

i fixed it, the problem was in user agent, thanks for your help