Использование встроенного модуля "http.client"
import http.client
connection = http.client.HTTPSConnection("api.bitbucket.org", timeout=2)
connection.request('GET', '/2.0/repositories')
response = connection.getresponse()
print('{} {} - a response on a GET request by using "http.client"'.format(response.status, response.reason))
content = response.read().decode('utf-8')
print(content[:100], '...')
Результат:
200 OK - ответ на запрос GET с использованием «http.client»
{"pagelen": 10, "values": [{"scm": "hg", "website": "", "has_wiki":
true, "name": "tweakmsg", "links ...
Использование сторонних библиотек "запросов"
response = requests.get("https://api.bitbucket.org/2.0/repositories")
print('{} {} - a response on a GET request by using "requests"'.format(response.status_code, response.reason))
content = response.content.decode('utf-8')
print(content[:100], '...')
Результат:
200 OK - ответ на запрос GET с использованием "http.client"
{"pagelen": 10, "values": [{"scm": "hg", "website": "", "has_wiki":
true, "name": "tweakmsg", "links ...
Использование встроенного модуля "urllib.request"
response = urllib.request.urlopen("https://api.bitbucket.org/2.0/repositories")
print('{} {} - a response on a GET request by using "urllib.request"'.format(response.status, response.reason))
content = response.read().decode('utf-8')
print(content[:100], '...')
Результат:
200 OK - ответ на запрос GET с использованием «http.client»
{"pagelen": 10, "values": [{"scm": "hg", "website": "", "has_wiki":
true, "name": "tweakmsg", "links ...
Примечания:
- Python 3.4
- Результат от ответов, скорее всего, будет отличаться только содержанием