Questions tagged [httpx]

HTTPX is a fully featured HTTP client for Python 3, which provides sync and async APIs, and support for both HTTP/1.1 and HTTP/2.

HTTPX is a fully featured HTTP client for Python 3, which provides sync and async APIs, and support for both HTTP/1.1 and HTTP/2. For more details, please check the HTTPX website.

162 questions
3
votes
3 answers

python asyncio & httpx

I am very new to asynchronous programming and I was playing around with httpx. I have the following code and I am sure I am doing something wrong - just don't know what it is. There are two methods, one synchronous and other asynchronous. They…
Ubaidul Khan
  • 131
  • 3
  • 13
3
votes
1 answer

fastapi throws 400 bad request when I upload a large file

I provisioned and configured a Fedora 34 vm on VirtualBox with 2048 MB RAM to serve this FastAPI application on localhost:7070. The full application source code and dependency code and instructions are here. Below is the smallest reproducible…
Matt Leader
  • 133
  • 1
  • 8
3
votes
0 answers

Best way to use httpx async client and tenacity?

I'm getting fairly different results with two different implementations. Here is implementation 1 request_semaphore = asyncio.Semaphore(5) async def _send_async_request(client: AsyncClient, method, auth, url, body): async with request_semaphore: …
JTa
  • 181
  • 1
  • 12
3
votes
0 answers

How can I use httpx to upload a file to S3 using a presigned url (PUT method)

As httpx aims to be compatible with the requests API wherever possible i tried the following based on this answer: with open(local_file, 'rb') as f: response = httpx.put(s3_presigned_url, data=f) This returns a 501 response from S3 with the…
agrav
  • 31
  • 5
3
votes
0 answers

Python asyncio vs ThreadPoolExecutor - inconsistent results for a purely I/O based task

I've recently come across the problem where one needs to fetch a list of URLs as quickly as possible. So naturally, I set up a small test to see what works best. Approach 1 - asyncio async def test_async(): async with httpx.AsyncClient() as…
Dev Aggarwal
  • 7,627
  • 3
  • 38
  • 50
2
votes
1 answer

Fastapi Testclient not able to send POST request using form-data

Currently I am doing Unit Testing in Fastapi using from fastapi.testclient import TestClient def test_login_api_returns_token(session,client): form_data = { "username": "mike@gmail.com", "password": "mike" } response =…
code_10
  • 155
  • 1
  • 2
  • 10
2
votes
1 answer

Monkeypatching/mocking the HTTPX external requests

I'm trying to monkeypatch the external request. Here is the code of a web endpoint: import httpx, json ... @app.get('/test') async def view_test(request): async with httpx.AsyncClient() as client: # sending external request api_response…
srbssv
  • 23
  • 2
2
votes
0 answers

httpx.RemoteProtocolError:

I am trying to create a webservice to update a wallet pass using apns push notifications. I am using httpx for this as it can use http/2. I have the following test code for this: import httpx import ssl import asyncio async def send_push(): …
2
votes
1 answer

how to pass form with files with names via httpx

I am trying to send data to gotenberg container via httpx lib. r = httpx.post( "http://doc-to-pdf:3000/forms/chromium/convert/html", files={ "index.html": file_bytes, }, params={ "marginTop": 0.4, …
Ryabchenko Alexander
  • 10,057
  • 7
  • 56
  • 88
2
votes
0 answers

why timeout did not work in an asyncClient?

I create a asyncClient by async with httpx.AsyncClient(proxies=proxies,timeout=2.0)as client: then I send a request print("get cookie res start", f'xid{xid}') cookieres = await client.get(url, headers=headers) print("get cookie res…
yg lin
  • 115
  • 9
2
votes
1 answer

fastapi/uvicorn prevent ungzipping with httpx.AsyncClinet

i work on reverse proxy based on fastapi. I want transparenty send data requested by AsyncClient. I have problem with gziped pages. Please can you help me, how to prevent default ungzipping of resp.content on this…
Jan Kortus
  • 23
  • 2
2
votes
0 answers

uvicorn random error "Invalid HTTP request received"

Using latest uvicorn[standard] 0.17.1. Tried config(timeout_keep_alive=0, http='h11',...) and the default (http='auto', which uses httptools). Using uvloop. Running server in another process; calling it using httpx. Keep getting "Invalid HTTP…
zpz
  • 354
  • 1
  • 3
  • 16
2
votes
0 answers

Sending JSON data as multipart-form data

I am trying to access an endpoint that is expecting multipart-form data: { "budget_id": 0, "file": "string" } with parameter content type application/json. I can access this endpoint via Postman, choosing a file that is JSON. However when I…
Ruth Smith
  • 41
  • 3
2
votes
1 answer

proxy an external website using python fast api not supporting query params

I am trying to proxy an external website (Flower monitoring URL running on different container) using python Fast API framework: client = AsyncClient(base_url=f'http://containername:7800/monitor') @app.get(“/monitor/{path:path}”) async def…
undefined
  • 3,464
  • 11
  • 48
  • 90
2
votes
0 answers

When using proxy my request is set to HTTP/1

Using the library httpx which allows me to make HTTP/2 request to target sites. However when I use the proxy it seem to automatically set my request to HTTP/1. I.e async def main(): client = httpx.AsyncClient(http2=True) response = await…
nardowick
  • 101
  • 1
  • 3
1
2
3
10 11