Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib.request
- import urllib.parse
- import ssl
- import requests
- from requests.auth import HTTPBasicAuth
- line =1
- try:
- line += 1#2
- myssl = ssl.create_default_context()#Bypass SSL verification when trying to access a secured website
- myssl.check_hostname = False
- myssl.verify_mode = ssl.CERT_NONE#SSL verification disabled
- USERNAME = '******'
- PASSWORD = '******'
- login_data = dict(username=USERNAME, password=PASSWORD)
- headers = {}
- headers['User-Agent'] = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.27 Safari/537.17"
- p = urllib.request.HTTPPasswordMgrWithPriorAuth()
- p.add_password(None,'https://bmh309668.rbeigcn.com:44330/sap/opu/odata/sap/IBAS_PLANT_MAINTENANCE_SRV/CodeGroups/',USERNAME,PASSWORD)
- handler = urllib.request.HTTPBasicAuthHandler(p)
- opener = urllib.request.build_opener(handler)
- urllib.request.install_opener(opener)
- line += 1#3
- data = urllib.parse.urlencode(login_data)
- data = data.encode('utf-8')#while using post we can send a byte format not a string so encode it to utf-8
- line += 1#4
- req = urllib.request.Request('https://bmh309668.rbeigcn.com:44330/sap/opu/odata/sap/IBAS_PLANT_MAINTENANCE_SRV/CodeGroups/',data=data, headers = headers)#request for the web page
- line += 1#5
- response = urllib.request.urlopen(req,context=myssl,data=data)#by using context=myssl we disable SSL verification
- line += 1#6
- #x = urllib.request.urlopen('https://bmh309668.rbeigcn.com:44330/sap/opu/odata/sap/IBAS_PLANT_MAINTENANCE_SRV/CodeGroups/',context=myssl,data=data)
- line += 1#7
- print(response.read())#print the data
- except Exception as e:
- print("Exception raised at line number: ",line)
- print(str(e))
Add Comment
Please, Sign In to add comment