Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if request post has been successfully posted?


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?

like image 422
ronnow Avatar asked Dec 11 '22 12:12

ronnow


1 Answers

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...
like image 59
Joakim Avatar answered Dec 13 '22 23:12

Joakim