0

Using the following command via cURL (Windows): curl -u username:password "https://website.com/update/" --data "simChangesList=%5B%7B%22simId%22%3A760590802%2C%22changeType%22%3A2%2C%22targetValue%22%3A%22000307%22%2C%22effectiveDate%22%3Anull%7D%5D" --compressed I am able to successfully post my data authenticated as per the -u switch.

How can I successfully create the same POST request using pycurl?

import urllib
import pycurl

enc = urllib.quote('simChangesList:[{"simId":760590802,"changeType":2,"targetValue":000307,"effectiveDate":null}]')
c = pycurl.Curl()
c.setopt(c.URL, 'https://website.com/update/')

c.setopt(c.POSTFIELDS, enc)
c.setopt(c.VERBOSE, True)

c.perform()
c.close()

Executing the above code will not POST the data I am wanting it to do, and I suspect it's because I'm requiring authentication, as per the Windows cURL version.

How can I successfully modify my code so that I can POST my data authenticated?

juiceb0xk
  • 949
  • 3
  • 19
  • 46
  • 1
    See [setting options](http://pycurl.io/docs/latest/quickstart.html#setting-options) and [`CURLOPT_USERPWD`](https://curl.haxx.se/libcurl/c/CURLOPT_USERPWD.html). But if you're going to be making a lot of web requests with python, I'd highly suggest checking out the [requests library](http://docs.python-requests.org/en/master/). – Daniel Underwood Jun 10 '17 at 10:05
  • This will help you: https://stackoverflow.com/a/6999774/4909087 – cs95 Jun 10 '17 at 10:05
  • @Coldspeed I'm using v2.7, not 3. – juiceb0xk Jun 10 '17 at 10:08
  • It will work for 2.7 as well. – cs95 Jun 10 '17 at 10:08

0 Answers0