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
1
vote
1 answer

How to test a FastAPI route that retries a SQLAlchemy insert after a rollback?

I have a route where I want to retry an insert if it failed due to an IntegrityError. I’m trying to test it using pytest and httpx but I get an error when I reuse the session to retry the insert after the rollback of the previous one. It works fine…
bfontaine
  • 18,169
  • 13
  • 73
  • 107
1
vote
2 answers

python httpx use --compressed like curl

How can I use httpx library to do something similar to curl --compressed "http://example.com" Meaning I want the library to check if server supports compression, if so send the right header and return the data to me as if it was not compressed?
Ehud Lev
  • 2,461
  • 26
  • 38
1
vote
1 answer

How to make requests in parallel using FastAPI

In FastAPI, I have this route: for id in ids: #get projects from list of ids p = await gitlab.project(id) if p and 'error' not in p: projects[int(id)] = p But it takes around 2sec per request sequentially, so I wait more than a…
MortenB
  • 2,749
  • 1
  • 31
  • 35
1
vote
1 answer

httpx POST request always gives "401 Unauthorized" before working fine the second attempt

I'm using async with httpx in a python script to make an HTTP POST request using DigestAuth. async with httpx.AsyncClient() as client: try: r = await client.post(f"http://{str(ip)}{setConfAddr}", auth=httpx.DigestAuth(username,…
1
vote
1 answer

using httpx to send 100K get requests

I'm using the httpx library and asyncio to try and send about 100K of get requests. I ran the code and received httpx.ConnectError so I opened wireshark and saw that I was getting a lot of messages saying TCP Retransmission TCP Port numbers reused…
Omer Dagry
  • 537
  • 4
  • 9
1
vote
0 answers

SqlAlchemy select hangs in FastAPI test setup

I developed a FastAPI app with WebSockets and I'm trying to test it. I need async tests in order to check data in the database during tests. My setup looks like this: I have a fixture that generates a database…
1
vote
1 answer

Deprecation error in venv/lib/python3.8/site-packages/httpx/_content.py:201:DeprecationWarning: Use 'content=<...>' to upload raw bytes/text content

I installed a project that has httpx in the code and it seems that there is a method deprecated in its code. I looked for a solution but I don't find any solution for it. ( Also, I have run it before and it was working "2 weeks ago"). The error…
Pain
  • 111
  • 1
  • 2
  • 12
1
vote
1 answer

How do I download PDF files using python's reqests/httpx module?

I'm making a program that downloads PDFs from the internet. Here's a example of the code: import httpx # <-- This also happens with the requests module URL =…
1
vote
0 answers

" Event loop is closed " error when reusing httpx client in flask

A very simple flask server gets requests from users and send a post request to an API , wanted to do this asynchronously using httpx (or even aiohttp) , it works fine like this @app.route('/test' , methods=['GET' , "POST"]) async def…
Antony
  • 263
  • 1
  • 2
  • 5
1
vote
1 answer

trio + httpx gives TrioDeprecationWarning

The following testcase gives a warning: import trio, httpx async def amain(): async with httpx.AsyncClient() as client: r = await client.get('https://icanhazip.com/') print(r.text) trio.run(amain) Output: > python …
P i
  • 29,020
  • 36
  • 159
  • 267
1
vote
1 answer

How to replace hyperlinks in StreamingResponse?

Is that possible to replace hyperlinks in StreamingResponse? I'm using below code to stream HTML content. from starlette.requests import Request from starlette.responses import StreamingResponse from starlette.background import…
Mateusz
  • 219
  • 2
  • 13
1
vote
2 answers

Python HTTPX | RuntimeError: The connection pool was closed while 6 HTTP requests/responses were still in-flight

I've come across this error multiple times while using the HTTPX module. I believe I know what it means but I don't know how to solve it. In the following example, I have an asynchronous function gather_players() that sends get requests to an API…
Tony
  • 266
  • 1
  • 11
1
vote
0 answers

closedResourceError intermittently when using httpx asyncclient to send the request

I'm observing closedResourceError when sending multiple requests using httpx async client. httpx version used is 0.19.0. Has anyone faced similar issue? if it is an issue and fixed in later version? Logs: resp = await…
Amit Jain
  • 11
  • 1
1
vote
1 answer

Scraping a website that is locked behind discord oauth (Trying to automate logging in with oauth with python requests)

I'm trying to automate a login on a popular website. This website uses Discord oauth. I have gotten to the stage where I have monitored the requests being made to discord (which contains the sites call-back URL. However, the issue I am facing is…
jaal kamza
  • 213
  • 4
  • 12
1
vote
1 answer

Is it necessary to write `async with AsyncClient`?

In the docs for httpx.AsyncClient, it says async with httpx.AsyncClient() as client: response = await client.get('https://example.org') Is this necessary? Why can't I write: async def get_client(): return AsyncClient() client = await…