Guest User

Untitled

a guest
Mar 27th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import urllib.request
  2. import urllib.parse
  3. import ssl
  4. import requests
  5. from requests.auth import HTTPBasicAuth
  6. line =1
  7. try:
  8.  
  9. line += 1#2
  10. myssl = ssl.create_default_context()#Bypass SSL verification when trying to access a secured website
  11. myssl.check_hostname = False
  12. myssl.verify_mode = ssl.CERT_NONE#SSL verification disabled
  13. USERNAME = '******'
  14. PASSWORD = '******'
  15. login_data = dict(username=USERNAME, password=PASSWORD)
  16.  
  17.  
  18. headers = {}
  19. headers['User-Agent'] = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.27 Safari/537.17"
  20. p = urllib.request.HTTPPasswordMgrWithPriorAuth()
  21. p.add_password(None,'https://bmh309668.rbeigcn.com:44330/sap/opu/odata/sap/IBAS_PLANT_MAINTENANCE_SRV/CodeGroups/',USERNAME,PASSWORD)
  22. handler = urllib.request.HTTPBasicAuthHandler(p)
  23. opener = urllib.request.build_opener(handler)
  24. urllib.request.install_opener(opener)
  25.  
  26.  
  27. line += 1#3
  28. data = urllib.parse.urlencode(login_data)
  29. data = data.encode('utf-8')#while using post we can send a byte format not a string so encode it to utf-8
  30. line += 1#4
  31. 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
  32. line += 1#5
  33. response = urllib.request.urlopen(req,context=myssl,data=data)#by using context=myssl we disable SSL verification
  34. line += 1#6
  35. #x = urllib.request.urlopen('https://bmh309668.rbeigcn.com:44330/sap/opu/odata/sap/IBAS_PLANT_MAINTENANCE_SRV/CodeGroups/',context=myssl,data=data)
  36. line += 1#7
  37. print(response.read())#print the data
  38.  
  39. except Exception as e:
  40. print("Exception raised at line number: ",line)
  41. print(str(e))
Add Comment
Please, Sign In to add comment