GET and PUT operation on HTTPS (with certificate error) in python
<p>I'm very new to python. The job assigned to me was to perform a put and get operation on one of the products web ui using python. I tried with the following code,</p>

<pre><code>import urllib2 
import ssl

try:
    response = urllib2.urlopen('https://the product web ui address') 
    print 'response headers: "%s"' % response.info() except IOError, e:
    if hasattr(e, 'code'): # HTTPError
        print 'http error code: ', e.code
    elif hasattr(e, 'reason'): # URLError
        print "can't connect, reason: ", e.reason
    else:
        raise
</code></pre>

<p>This is raising an error:</p>

<blockquote>
  <p>can't connect, reason:  [SSL: CERTIFICATE_VERIFY_FAILED] certificate
  verify failed (_ssl.c:590)</p>
</blockquote>

<p>The url, while accessing through browser will show that it is having a certificate error. We need to click on proceed to go to the url. Can somebody help me with a way to perform put and get operation on such a uri. Sorry if this question seems dumb, thanks for the support.</p>

<p>Also, i tried with requests. Attaching the code. It also gives the same error</p>

<pre><code>import requests
import sys

try:

    r = requests.get("https://the product web ui address")
    data = r.content
    print r.status_code
    print data
except:
    print "Error Occured ",sys.exc_info()[0]
</code></pre>

<p>The error is : </p>

<blockquote>
  <p><strong>Error Occured  class 'requests.exceptions.SSLError'</strong></p>
</blockquote>

<p>I got it. </p>

<pre><code>import requests
import sys

try:

    r = requests.get("https://web ui address",verify=False)
    data = r.content
    f = open('myfile.xml','w')
    f.write(data)
    f.close()
    print "Status Code returned : " ,r.status_code
except:
    print "Error Occured ",sys.exc_info()[0]
</code></pre>

<p>Adding <strong>verify=False</strong>, solved my problem.Now it throws a warning but no errors. Its working fine.</p>

python ssl get httprequest put