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
16
votes
2 answers

how do you properly reuse an httpx.AsyncClient within a FastAPI application?

I have a FastAPI application which, in several different occasions, needs to call external APIs. I use httpx.AsyncClient for these calls. The point is that I don't fully understand how I shoud use it. From httpx' documentation I should use context…
japs
  • 1,286
  • 13
  • 27
7
votes
1 answer

python/httpx/asyncio: httpx.RemoteProtocolError: Server disconnected without sending a response

I am attempting to optimize a simple web scraper that I made. It gets a list of urls from a table on a main page and then goes to each of those "sub" urls and gets information from those pages. I was able to successfully write it synchronously and…
ab217
  • 16,900
  • 25
  • 74
  • 92
7
votes
2 answers

How to disable server exceptions on fast-api when testing with httpx AsyncClient?

We have a FastApi app and using httpx AsyncClient for testing purposes. We are experiencing a problem where the unit tests run locally fine but fail on the CI server (Github Actions). After further research we have come across this proposed solution…
Houman
  • 64,245
  • 87
  • 278
  • 460
7
votes
3 answers

Yielding asyncio generator data back from event loop possible?

I would like to read from multiple simultanous HTTP streaming requests inside coroutines using httpx, and yield the data back to my non-async function running the event loop, rather than just returning the final data. But if I make my async…
gwtwod
  • 73
  • 5
5
votes
2 answers

ModuleNotFoundError: No module named 'httpx'

Getting above error have installing the correct package Python --version Python 3.6.9 Install command pip3 install httpx pip3 list anyio (3.6.1) async-generator (1.10) Brotli (1.0.9) certifi (2022.6.15) charset-normalizer (2.1.0) contextvars…
saurabh kamble
  • 1,510
  • 2
  • 25
  • 42
5
votes
1 answer

Different results between requests.get and aiohttp GET and Httpx module

I am trying to access a site with a bot prevention. with the following script using requests I can access the site. request = requests.get(url,headers={**HEADERS,'Cookie': cookies}) and I am getting the desired HTML. but when I use aiohttp async…
Daniel Botnik
  • 539
  • 1
  • 6
  • 20
4
votes
1 answer

how limit request per second with httpx [Python 3.6]

My project consists of consuming an api that is built on top of the aws lambda service. Technically, the leader who built the api tells me that there is no fixed request limit since the service is elastic, but it is important to take into account…
Joan
  • 269
  • 1
  • 3
  • 10
4
votes
1 answer

How to Use Elsevier Article Retrieval API to get fulltext of paper

I want to use Elsevier Article Retrieval API (https://dev.elsevier.com/documentation/FullTextRetrievalAPI.wadl) to get fulltext of paper. I use httpx to get the information of the paper,but it just contains some information.My code is below: import…
Fighting
  • 99
  • 1
  • 10
4
votes
2 answers

how to use httpx.AsyncClient as class member, and close asynchronously

I want to use http client as a class member, but del function could not call await client.aclose(). e.g.: import httpx class Foo(object): def __init__(self): self.client = httpx.AsyncClient() def __del__(self): await…
whi
  • 2,685
  • 6
  • 33
  • 40
4
votes
2 answers

Python: Cannot install googletrans

I try to install googletrans https://pypi.org/project/googletrans/ by running this command as adviced: $ pip install googletrans but I always get same error both at python 3.5 and python 2.7: Collecting googletrans Using cached…
4
votes
2 answers

uploading multiple files UploadFiles FastAPI

Example Here's my code: from typing import List from fastapi import FastAPI, File, UploadFile import asyncio import concurrent.futures app = FastAPI() @app.post("/send_images") async def update_item( files: List[UploadFile] = File(...), ): …
Danil Kononyhin
  • 196
  • 1
  • 16
3
votes
1 answer

How to trap this nested httpx exception?

I'm trapping thus: with httpx.Client(**sessions[scraperIndex]) as client: try: response = client.get(...) except TimeoutError as e: print('does not hit') except Exception as e: print(f'⛔️ Unexpected exception:…
P i
  • 29,020
  • 36
  • 159
  • 267
3
votes
4 answers

How to mock httpx.AsyncClient() in Pytest

I need to write test case for a function which use to fetch data from API. In there i used httpx.AsyncClient() as context manager. But i don't understand how to write test case for that function. async def make_dropbox_request(url, payload,…
3
votes
1 answer

Python & HTTPX: How does httpx client's connection pooling work?

Consider this function that makes a simple GET request to an API endpoint: import httpx def check_status_without_session(url : str) -> int: response = httpx.get(url) return response.status_code Running this function will open a new TCP…
Redowan Delowar
  • 1,580
  • 1
  • 14
  • 36
3
votes
1 answer

Using a context manager as a global dependency in Fast API

I have a FastAPI app that mostly calls external apis. In some instances, a path operation will make several calls to the same host. For that reason, I want to use a single httpx AsyncClient for each request. The correct way to do this seems to be…
notxapw4
  • 83
  • 1
  • 7
1
2 3
10 11