-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathgiturl.py
More file actions
32 lines (25 loc) · 743 Bytes
/
giturl.py
File metadata and controls
32 lines (25 loc) · 743 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
30
31
import urllib.request, urllib.parse, urllib.error
import ssl
import gitsecrets
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
def urlopen(url):
secrets = gitsecrets.secrets()
parms = urllib.parse.urlencode(secrets)
if url.find('?') > 0 :
url = url + '&'
else:
url = url + '?'
url = url + parms
# print('Retrieving', url)
req = urllib.request.Request(
url,
data=None,
headers={'User-Agent': 'giturl.py from www.py4e.com/code3'
}
)
connection = urllib.request.urlopen(req, context=ctx)
str_json = connection.read().decode()
headers = dict(connection.getheaders())
return (str_json, headers)