Source: Requests
← Renderedmarkdown source:
---
description: Requests - обработка http-запросов в python
tags: http crawlers pip python
title: Requests
---
http-библиотечка на python для запросов/ответов.
Пример
```python
>>> r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
>>> r.status_code
200
>>> r.headers['content-type']
'application/json; charset=utf8'
>>> r.encoding
'utf-8'
>>> r.text
'{"type":"User"...'
>>> r.json()
{'private_gists': 419, 'total_private_repos': 77, ...}
```
## How to send request_body encoded as application/x-www-form-urlencoded
Это требуется, к примеру, при реализации bearer [[http]] схемы аутентификации
```python
...
endpoint = "some url"
data={"username": f"{login}", "password": f"{password}"}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
response = requests.post(endpoint, data=data, headers=headers)
print(response)
```
[Подробнее на stackoverflow](https://stackoverflow.com/questions/62886283/python-requests-post-how-to-send-request-body-encoded-as-application-x-www-fo)
Смотри еще:
- [[http-requests-errors]]
- [grequests](https://github.com/spyoungtech/grequests) GRequests allows you to use Requests with Gevent to make asynchronous HTTP Requests easily.
- [requests-futures](https://github.com/ross/requests-futures) Asynchronous Python HTTP Requests for Human
- [requests-threads](https://github.com/requests/requests-threads) This repo contains a Requests session that returns the amazing Twisted's awaitable Deferreds instead of Response objects
- [[aiohttp]]
[http]: ../lists/http "Http"
[http-requests-errors]: http-requests-errors "Http requests"
[aiohttp]: aiohttp "Aiohttp асинхронный клиент-свервер на python."