Python 3.6.1 Service calls using GET and POST method

python-logo-master-v3-tm
In this python 3.6.1 version, have faced the issues to run the script. At the moment, I get the error. Below shows that
Error:
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>
Can you read this forum. You will get the solution. The problem is occurring in the certification updating.

https://bugs.python.org/issue28150

 

After we will use the script to run the  script successfully.

import urllib.parse
import urllib.request
import json
from urllib.error import URLError, HTTPError
urlValue = “https://google.com
posturlValue = “https://google.com
def getMethod(urlName):
    req = urllib.request.Request(urlName)
    try:
        response = urllib.request.urlopen(req)
    except HTTPError as e:
        # do something
        print(‘Error code: ‘, e.code)
        return e.code
    except URLError as e:
        # do something
        print(‘Reason: ‘, e.reason)
        return e.reason
    else:
        # do something
        print(“”,response.read())
        print(‘good!’)
        return response.read()
def postMethod(urlName):
    try:
        objs = {“id”:”TV”,”AV”:’0′,”Exit”:’0′}
        data = urllib.parse.urlencode(objs).encode(“utf-8”)
        req = urllib.request.Request(urlName, data)
        response = urllib.request.urlopen(req)
        result = response.read()
        print (“Server response is: “,result)
        return result
    except Exception as ex:
        print (“”,ex)
 #run the methods
postMethod(posturlValue)
getMethod(urlValue)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s