Skip to content

Commit 3e46a76

Browse files
committed
urllib examples
1 parent 3bc0bd9 commit 3e46a76

10 files changed

+70
-0
lines changed
400 Bytes
Binary file not shown.

__pycache__/logging.cpython-37.pyc

256 Bytes
Binary file not shown.

checking ssl.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import certifi
2+
import urllib3
3+
4+
5+
http = urllib3.PoolManager(
6+
cert_reqs = 'CERT_REQUIRED',
7+
ca_certs = certifi.where()
8+
)
9+
10+
site = 'https://facebook.com' #site you want to test
11+
try:
12+
r = http.request('GET',site)
13+
if r.status == 200:
14+
print("SSL is OK, site is accessable in your region")
15+
else:
16+
print(f"SSL Found, but there something wrong to access the website, {r.status}")
17+
except:
18+
print("SSL is not found")

example.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is an example of this tutorials.

file data.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import urllib3
2+
import json
3+
http = urllib3.PoolManager()
4+
5+
with open('example.txt') as fp:
6+
file_data = fp.read()
7+
r = http.request(
8+
'POST',
9+
'http://httpbin.org/post',
10+
fields ={'filefield':('example.txt',file_data)})
11+
12+
print(json.loads(r.data.decode('utf-8'))['files'])

form data.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import urllib3 as url
2+
import json
3+
http = url.PoolManager()
4+
5+
r = http.request(
6+
'POST',
7+
'http://httpbin.org/post',
8+
fields={'field': 'value'})
9+
10+
print(json.loads(r.data.decode('utf-8')))

get ip address.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import urllib3 as url
2+
3+
http = url.PoolManager()
4+
5+
request = http.request('GET', 'http://httpbin.org/ip')
6+
print(request.data)

post and put request.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from urllib.parse import urlencode
2+
import json
3+
import urllib3 as url
4+
http = url.PoolManager()
5+
6+
7+
encoded_args = urlencode({'arg': 'value'})
8+
url = 'http://httpbin.org/post?' + encoded_args
9+
r = http.request('POST', url)
10+
print(json.loads(r.data.decode('utf-8'))['args'])

proxy manager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import urllib3
2+
proxy = urllib3.ProxyManager('http://localhost:3128/')
3+
proxy.request('GET', 'http://google.com/')

url_lib3.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import urllib3 as url
2+
import json
3+
http = url.PoolManager()
4+
5+
# request = http.request('GET','http://google.com')
6+
# print(request.status)
7+
# print(request.headers)
8+
9+
request = http.request('GET', 'http://httpbin.org/ip')
10+
print(json.loads(request.data.decode('utf-8')))

0 commit comments

Comments
 (0)