Python / Requests - Can't send POST properly, despite it is working in Postman

Chainsaw

everyone. I have following code:

url = "url"
headers = {'Content-type': 'application/json'}

bot = telebot.TeleBot('xxx')



@bot.message_handler(commands=['start'])
def start_message(message):
    bot.send_message(message.chat.id, message.chat.id)
    bot.send_message(message.chat.id, message.chat.username)
    data = {"userId": "message.chat.username", "chatId": "message.chat.id"}
    answer = requests.post(url, data=data, headers=headers)
    print(answer)

Answer is 400. But when I use Postman with raw JSON: {"userId":"xxx", "chatId": "xxx"}

It gives me 200.

Can't understand the difference. Thank you.

Sparrow_ua

Maybe problem with data. No?

data = {"userId": f"{message.chat.username}", "chatId": f"{message.chat.id}"}

instead of

data = {"userId": "message.chat.username", "chatId": "message.chat.id"}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

POST Request in Python 'requests' module not working properly

Why can't I send `None` as data in a POST request using Python's `requests` library?

Postman Post not working despite the API working everywhere else

Python Requests POST not working

Postman can't be opened properly

VB.NET Can't send POST request properly

Python requests timeout not working properly

python can't send post request image

Can't post with postman, why?

Can't post data with postman

Creating a pure python API (without any framework) where postman client can successfully post json requests

Can't post file using python requests - Translation from curl

Python requests library can't specify JSON key on HTTP POST

Python requests post error.. can't decoding

Python requests - post method - send image from CV2 - ndarray not working

Python Requests post times out despite timeout setting

I can't get my data back, The Post function is working fine, tested with postman

Python Requests: How can I properly submit a multipart/form POST using a file name

Can't properly send Request Body on the node.js version of XMLHttpRequest when doing POST request

Java can't display Unicode characters despite properly configured terminal

Can not send POST variables to php script on localhost using Postman

cURL POST request not working as python requests equivalent

Python Requests POST url encoded request not working

Python re not working with requests' POST response

python > requests module > post > headers not working

flask can't get post data from postman or web page,but work in python request

can't parse JSON from a post requests

Can I send **kwargs in place of set parameter in requests.post?

Django can't save comment to post properly