ImportError: cannot import name 'SOCKET_OPTION' from 'httpcore.backends.base' #2746
-
I am trying to make a request from an API using httpx, I am getting the following error. Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\Python310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Program Files\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
return future.result()
File "<stdin>", line 20, in main
File "C:\Users\abu aisha\Documents\AI-Whatsapp-Photo-Editor-Chat-Bot\venv\lib\site-packages\httpx\_client.py", line 1533, in request
async def stream(
File "C:\Users\abu aisha\Documents\AI-Whatsapp-Photo-Editor-Chat-Bot\venv\lib\site-packages\httpx\_client.py", line 1620, in send
follow_redirects=follow_redirects,
File "C:\Users\abu aisha\Documents\AI-Whatsapp-Photo-Editor-Chat-Bot\venv\lib\site-packages\httpx\_client.py", line 1648, in _send_handling_auth
history=history,
File "C:\Users\abu aisha\Documents\AI-Whatsapp-Photo-Editor-Chat-Bot\venv\lib\site-packages\httpx\_client.py", line 1685, in _send_handling_redirects
await hook(response)
File "C:\Users\abu aisha\Documents\AI-Whatsapp-Photo-Editor-Chat-Bot\venv\lib\site-packages\httpx\_client.py", line 1722, in _send_single_request
response.request = request
File "C:\Users\abu aisha\Documents\AI-Whatsapp-Photo-Editor-Chat-Bot\venv\lib\site-packages\httpx\_transports\default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "C:\Users\abu aisha\Documents\AI-Whatsapp-Photo-Editor-Chat-Bot\venv\lib\site-packages\httpcore\_async\connection_pool.py", line 253, in handle_async_request
# up as HTTP/1.1.
File "C:\Users\abu aisha\Documents\AI-Whatsapp-Photo-Editor-Chat-Bot\venv\lib\site-packages\httpcore\_async\connection_pool.py", line 237, in handle_async_request
# up the exception.
File "C:\Users\abu aisha\Documents\AI-Whatsapp-Photo-Editor-Chat-Bot\venv\lib\site-packages\httpcore\_async\connection.py", line 86, in handle_async_request
origin=self._origin,
File "C:\Users\abu aisha\Documents\AI-Whatsapp-Photo-Editor-Chat-Bot\venv\lib\site-packages\httpcore\_async\connection.py", line 63, in handle_async_request
f"Attempted to send request to {request.url.origin} on connection to {self._origin}"
File "C:\Users\abu aisha\Documents\AI-Whatsapp-Photo-Editor-Chat-Bot\venv\lib\site-packages\httpcore\_async\connection.py", line 111, in _connect
"port": self._origin.port,
File "C:\Users\abu aisha\Documents\AI-Whatsapp-Photo-Editor-Chat-Bot\venv\lib\site-packages\httpcore\backends\auto.py", line 28, in connect_tcp
socket_options: typing.Optional[typing.Iterable[SOCKET_OPTION]] = None,
File "C:\Users\abu aisha\Documents\AI-Whatsapp-Photo-Editor-Chat-Bot\venv\lib\site-packages\httpcore\backends\auto.py", line 17, in _init_backend
else:
File "C:\Users\abu aisha\Documents\AI-Whatsapp-Photo-Editor-Chat-Bot\venv\lib\site-packages\httpcore\backends\asyncio.py", line 16, in <module>
from .base import SOCKET_OPTION, AsyncNetworkBackend, AsyncNetworkStream
ImportError: cannot import name 'SOCKET_OPTION' from 'httpcore.backends.base' (C:\Users\abu aisha\Documents\AI-Whatsapp-Photo-Editor-Chat-Bot\venv\lib\site-packages\httpcore\backends\base.py) I have uninstalled and installed httpx, but it still returns the same error. from dotenv import load_dotenv
import os
import httpx
import json
import asyncio
import httpcore.backends.base
from httpcore.backends.base import SOCKET_OPTION
load_dotenv()
async def main():
async with httpx.AsyncClient() as client:
process_url = "https://api.monsterapi.ai/apis/add-task"
process_payload = json.dumps({
"model": "pix2pix",
"data": {
"prompt": "Moutain View",
"negprompt": "",
"steps": 50,
"guidance_scale": 12.5,
"init_image_url": "https://media.gq-magazine.co.uk/photos/63468efef4f48bee2acb7062/16:9/pass/Tom-Holland-Spiderman-what-we-know-so-far.jpg",
"image_guidance_scale": 1.5
}
})
process_headers = {
'x-api-key': os.getenv("MONSTER_KEY"),
'Authorization': os.getenv("MONSTER_TOKEN"),
'Content-Type': 'application/json'
}
process_response = await client.request("POST", process_url, headers=process_headers, data=process_payload)
process_id = process_response.json()["process_id"]
url = "https://api.monsterapi.ai/apis/task-status"
payload = json.dumps({
"process_id": process_id
})
headers = {
'x-api-key': os.getenv("MONSTER_KEY"),
'Authorization': os.getenv("MONSTER_TOKEN"),
'Content-Type': 'application/json'
}
response = await client.request("POST", url, headers=headers, data=payload)
asyncio.run(main()) |
Beta Was this translation helpful? Give feedback.
Answered by
karpetrosyan
Jun 19, 2023
Replies: 2 comments 8 replies
-
Hi! This is due to the fact that the most recent version of httpx requires httpcore version "0.17.2" or higher. pip install httpcore --upgrade |
Beta Was this translation helpful? Give feedback.
4 replies
-
Thanks @karosis88 |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your Python script appears to be running in a different virtual environment.
Check that your environment settings are correct.