Search code examples
pythonwebcurlpostpycurl

Python pycurl post values to a web form really simple


All I want to do is convert this curl code to pycurl:

curl -d "username=Bruce&submit=Submit" "https://mytestwebsite.com/testingcurl"

So all it's gonna do is send the username "Bruce" and submit. Yet, all the examples I've looked at have been hideously complicated. Not quite sure why this is so difficult!


Solution

  • You can do it quickly and simply with requests module, It's simpler and easier:

    import requests
    
    data = {
      'username': 'Bruce',
      'submit': 'Submit'
    }
    
    response = requests.post('https://mytestwebsite.com/testingcurl', data=data)
    

    As you've probably seen, with `pycurl` you will have to use the `setopt` methods and then use `perform`, `requests` is simpler.