Search code examples
pythoncurlamazon-s3pycurl

How to pass encoded Amazon s3 signed URL in python curl Postfields?


I need to pass an amazon s3 signed URL to my python cURL function. The signed url have some special characters as '%' which is passed to the cURL POSTFIELDS and after the processing I am getting 500 Internal Server error. Is there a way to pass the POSTFIELDS in encoded format so cURL can process it?


Solution

  • import urllib
    import pycurl
    
    def urlconvert:
      wrapper = {'filename':p} # p is the amazon s3 signed url
      c = pycurl.Curl()
      c.setopt(pycurl.URL, url) #url is the url for curl request
      c.setopt(pycurl.POST, 1)
      post_args = urllib.urlencode(wrapper)
      c.setopt(pycurl.POSTFIELDS, post_args)