Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am using python requests HTTP POST to send a data to a certain third-party website I do not own. But I can't get it to work because I am getting 414 status code.

url = "http://someurl.com"
headers = {
   'Content-Type': "application/x-www-form-urlencoded; charset=UTF-8"
params = {'input': "Lorem ipsum... very long string"}
result = requests.post(url, params=params, headers=headers)
print(result.status_code)

How can I get this to work?

That's an error from their server - you can't fix it on your end. Can you use a shorter string? (B/c 414 is "URL too long to process") – David Manheim Oct 9, 2015 at 4:13 Are you sure you don't to pass params as the "data" eg. requests.post(url, data=params, headers=headers) – John La Rooy Oct 9, 2015 at 4:18 @John La Rooy, it worked for params for a limited string, now I used the data arg, and yeah, it worked. Thanks. – macdelacruz Oct 10, 2015 at 5:03

Looking at the docs, it seems that result = requests.post(url, params=params, headers=headers) should be result = requests.post(url, data=params, headers=headers) (credit to John La Rooy).

IIRC the params flag means the params you see tacked onto the end of your url, while data is the POST data.

I used Firebug to find how to post the data to a site. I looked at parameters in the Request method and found an "input" parameter where I can inject data. It worked fine for up to around 1000 characters string. Now I tried with your suggestion, using data instead of params, and voila, it worked! Thanks. – macdelacruz Oct 10, 2015 at 5:00 @MarkAnthonyDelaCruz If this solved your problem, please consider clicking the "accept answer" button and upvote :) <3 – Snakes and Coffee Oct 10, 2015 at 5:56

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.