'Response 405 using Python Requests

I try to send form data to the following url: https://peepoo.gq I have tried adding headers, and almost everything in the chrome network log that a normal browser sends, but I am always left with error 405. My code:

import requests

url = 'https://peepoo.gq/'

payload = {'content' : 'bruh'}

headers = {
'accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
'content-type' : 'application/x-www-form-urlencoded',
'accept-encoding' : 'gzip, deflate, br',
'accept-language' : 'en-US,en;q=0.9',
'cache-control' : 'max-age=0',
'content-length' : '12',
'dnt' : '1'
}

params = {'guestbook_name' : 'main'}

r = requests.post(url, data=payload, headers=headers, params=params, allow_redirects=False)


print(r)


Solution 1:[1]

The following code is working for me:

import requests

url = 'https://peepoo.gq/sign'

payload = {'content' : 'pickle rick'}

headers = {
'content-type' : 'application/x-www-form-urlencoded',
}

params = {'guestbook_name' : 'main'}

r = requests.post(url, data=payload, headers=headers, params=params, allow_redirects=True)

basically, you need to allow redirects and your url needs to point to https://peepoo.gq/sign

Solution 2:[2]

You are using a POST method what is not accepted (said already by Klaus D.) and using the data parameter, what passes the information to the POST method also.

Apart from that you are passing twice the following key value pair: 'guestbook_name' : 'main' Once in the url and once in the params.

Solution 3:[3]

I got 405 HTTP error, because of the default User-Agent: python-requests/2.27.1 header that requests module sends . Changing User-Agent header helped me:

import requests

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36'
}
url = 'https://example.com/some-path'
data = {'a': 1}

r = requests.post(url, data=data, headers=headers, allow_redirects=True)
print(r.status_code)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 yesnik