0

I want to login into a website sending POST request using `pycurl' on a HTTPS page. I did the following:

import pycurl, urllib
curl = pycurl.Curl()
curl.setopt(pycurl.COOKIEFILE, "")
post = "_username=something&_password=somethingelse&_submit=Login"
curl.setopt(pycurl.URL, "https://www.example.com/login_check")
curl.setopt(pycurl.POST, 1)
curl.setopt(pycurl.POSTFIELDS, post)
curl.perform()

But I wasn't able to login. May be that was because my code made http call rather. Although I am able to perform the login sending 'POST' request with the same parameters in `POSTMAN'

So seems like login is right but I am doing something wrong implementing the same in python. Pl guide.

codersofthedark
  • 9,183
  • 8
  • 45
  • 70
  • 1
    When you say that it didn't work, can you provide us with an error message and/or a description of what you expect to happen and what it is happening instead? – Mikk Nov 18 '14 at 16:06

1 Answers1

0

According to the pycURL documentation, your post data needs to be key value pairs and url encoded:

post_data = {'field': 'value'}
# Form data must be provided already urlencoded.
postfields = urlencode(post_data)
# Sets request method to POST,
# Content-Type header to application/x-www-form-urlencoded
# and data to send in request body.
c.setopt(c.POSTFIELDS, postfields)
Paul Trott
  • 209
  • 5
  • 7
  • the content I am passing is already encoded ;) Like in your case, if `post_data = {'field1': 'value1', 'field2':'value2'}` then postfields would be `field2=value2&field1=value1` so I don't think that is an issue. – codersofthedark Nov 19 '14 at 04:48
  • Can you post the server response? – Paul Trott Dec 16 '14 at 19:30