Ad

Error While Sending POST Request With Data

- 1 answer

I tried to create program which will create account on this site: https://www.kostkuj.cz/register My main problem is that i dont really know how it works, so i re-builded one project to my requirements.

I also tried sending requests with login data as parsed text:

    email: "[email protected]"
    plainPassword: {first: "pass1", second: "pass1"}
    first: "pass1"
    second: "pass1"
    username: "username3" 

But i dont know what i am doing wrong.

This is my whole code:

import requests


headers = {
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 OPR/63.0.3368.71'
}

register_data = {
    {"username":"username3","email":"[email protected]","plainPassword":{"first":"pass1","second":"pass1"}}
}

with requests.Session() as s:
    url = 'https://api.kostkuj.cz/register'
    r = s.get(url, headers=headers)
    r = s.post(url, data=register_data, headers=headers)
    print(r.content)

I am getting error like:

Traceback (most recent call last):
 File "C:\Users\jiris\Desktop\spamkostkuj.py", line 9, in <module>
   {"username":"username3","email":"[email protected]","plainPassword":{"first":"pass1","second":"pass1"}}
TypeError: unhashable type: 'dict'
Ad

Answer

First thing headers needs ro in pair i.e. key value pair. In your case somthing like:

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 OPR/63.0.3368.71'
}

Secondly, your are sending data as dict of dict which is incorrect, instead send a dict, like:

register_data = {"username":"username3","email":"[email protected]","plainPassword":{"first":"pass1","second":"pass1"}}

Try this. Hopefully is should work for you.

Ad
source: stackoverflow.com
Ad