PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, November 24, 2022

[FIXED] How to check if request post has been successfully posted?

 November 24, 2022     http, module, python, python-requests     No comments   

Issue


I'm using the python requests module to handle requests on a particular website i'm crawling. I'm fairly new to HTTP requests, but I do understand the basics. Here's the situation. There's a form I want to submit and I do that by using the post method from the requests module:

# I create a session
Session = requests.Session()
# I get the page from witch I'm going to post the url
Session.get(url)
# I create a dictionary containing all the data to post
PostData = {
  'param1': 'data1',
  'param2': 'data2',
}
# I post
Session.post(SubmitURL, data=PostData)

Is there a any ways to check if the data has been successfully posted? Is the .status_code method a good way to check that?


Solution

If you pick up the result from when you post you can then check the status code:

result = Session.post(SubmitURL, data=PostData)
if result.status_code == requests.codes.ok:
    # All went well...


Answered By - Joakim
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing