-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthoRequest.py
More file actions
29 lines (25 loc) · 990 Bytes
/
AuthoRequest.py
File metadata and controls
29 lines (25 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
try:
from getUnamePassAuth import unamePass
#if this file with username and password exists
# authenticate otherwise dont.
print('Authenticating . . .')
from urllib.request import build_opener, HTTPSHandler, HTTPError, Request
import base64
def AuthoRequest(url):
username, password = unamePass()
userandpass = base64.b64encode(bytes('%s:%s' % (username, password), 'utf-8'))
userandpass = userandpass.decode('ascii')
authorization = 'Basic %s' % userandpass
opener = build_opener(HTTPSHandler)
request = Request(url)
request.add_header('Authorization', authorization)
response = opener.open(request)
return response.read()
except ImportError:
from urllib.request import Request, urlopen
print('Not Authenticating . . .')
def AuthoRequest(url):
req = Request(url)
with urlopen(req) as response:
the_page = response.read()
return the_page