Skip to content

Instantly share code, notes, and snippets.

@SidJain1412
Created May 11, 2023 11:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save SidJain1412/ac7713d170372f5f25513ef58d4c6c24 to your computer and use it in GitHub Desktop.
Calling a Streaming API using requests library in Python
import requests
url = "http://127.0.0.1:8000/campaign/?prompt=Pepsi"
response = requests.get(
url,
stream=True,
headers={"accept": "application/json"},
)
for chunk in response.iter_content(chunk_size=1024):
if chunk:
print(str(chunk, encoding="utf-8"), end="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment