Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpx.ConnectError #406

Closed
cboutaud opened this issue Dec 27, 2022 · 4 comments
Closed

httpx.ConnectError #406

cboutaud opened this issue Dec 27, 2022 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@cboutaud
Copy link

I get the following error when running ghunt gaia [TARGET GAIA ID] from the terminal, any ideas of what the problem might be?

Traceback (most recent call last):
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/trio/_ssl.py", line 468, in _retry
ret = fn(*args)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 974, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions
yield
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpcore/backends/trio.py", line 80, in start_tls
raise exc
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpcore/backends/trio.py", line 77, in start_tls
await ssl_stream.do_handshake()
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/trio/_ssl.py", line 640, in do_handshake
await self._handshook.ensure(checkpoint=True)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/trio/_ssl.py", line 221, in ensure
await self._afn(*self._args)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/trio/_ssl.py", line 610, in _do_handshake
await self._retry(self._ssl_object.do_handshake, is_handshake=True)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/trio/_ssl.py", line 473, in _retry
raise trio.BrokenResourceError from exc
trio.BrokenResourceError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
yield
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
raise exc
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
response = await connection.handle_async_request(request)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpcore/_async/connection.py", line 86, in handle_async_request
raise exc
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpcore/_async/connection.py", line 63, in handle_async_request
stream = await self._connect(request)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpcore/_async/connection.py", line 150, in _connect
stream = await stream.start_tls(**kwargs)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpcore/backends/trio.py", line 74, in start_tls
with map_exceptions(exc_map):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py", line 153, in exit
self.gen.throw(typ, value, traceback)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
raise to_exc(exc)
httpcore.ConnectError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/cboutaud/.local/bin/ghunt", line 8, in
sys.exit(main())
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/ghunt/ghunt.py", line 15, in main
parse_and_run()
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/ghunt/cli.py", line 31, in parse_and_run
process_args(args)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/ghunt/cli.py", line 44, in process_args
trio.run(gaia.hunt, None, args.gaia_id, args.json)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/trio/_core/_run.py", line 1946, in run
raise runner.main_task_outcome.error
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/ghunt/modules/gaia.py", line 28, in hunt
is_found, target = await people_pa.people(as_client, gaia_id, params_template="max_details")
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/ghunt/apis/peoplepa.py", line 169, in people
await person._scrape(as_client, person_data)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/ghunt/parsers/people.py", line 150, in _scrape
await person_photo._scrape(as_client, photo_data, "profile_photo")
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/ghunt/parsers/people.py", line 60, in _scrape
self.isDefault, self.flathash = await is_default_profile_pic(as_client, self.url)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/ghunt/helpers/utils.py", line 63, in is_default_profile_pic
flathash = await get_url_image_flathash(as_client, image_url)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/ghunt/helpers/utils.py", line 52, in get_url_image_flathash
req = await as_client.get(image_url)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpx/_client.py", line 1757, in get
return await self.request(
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpx/_client.py", line 1533, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpx/_client.py", line 1620, in send
response = await self._send_handling_auth(
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpx/_client.py", line 1648, in _send_handling_auth
response = await self._send_handling_redirects(
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpx/_client.py", line 1685, in _send_handling_redirects
response = await self._send_single_request(request)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpx/_client.py", line 1722, in _send_single_request
response = await transport.handle_async_request(request)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
with map_httpcore_exceptions():
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py", line 153, in exit
self.gen.throw(typ, value, traceback)
File "/Users/cboutaud/.local/pipx/venvs/ghunt/lib/python3.10/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ConnectError

@cboutaud
Copy link
Author

cboutaud commented Dec 28, 2022

I've tried using GHunt as a lib instead of calling from the terminal and using the following code, based on get_people_name.py from the examples, the script runs as expected with params_template="just_name" but runs into basically the same error as above with params_template="max_details", so I assume it's an issue with ssl when we're making concurrent calls? Still I am not sure where to look to fix this...

Here's the code based on get_people_name.py

import httpx
import trio

from ghunt.apis.peoplepa import PeoplePaHttp
from ghunt.objects.base import GHuntCreds

gaia = "[TARGET GAIA ID]"

async def get_details_from_gaia(gaia):
	# This object stores all the needed credentials that GHunt uses
	ghunt_creds = GHuntCreds()
	# Check creds (but it doesn't crash if they are invalid)
	ghunt_creds.load_creds()

	# Async clientb
	as_client = httpx.AsyncClient()

	# Get the GHunt people api
	people_api = PeoplePaHttp(ghunt_creds)
	found, person = await people_api.people(as_client, gaia, params_template="max_details")

	print("Found:", found)
	if found:
		# A specification of People API, there are different containers
		# A target may not exists globally, but only in your contacts,
		# so it will show you only the CONTACT container,
		# with the informations you submitted.
		# What we want here is the PROFILE container, with public infos.
		if "PROFILE" in person.names:
			print("Name:", person.names["PROFILE"].fullname)
		else:
			print("Not existing globally.")

# Running our async code in a non-async code
trio.run(get_details_from_gaia, gaia)

@cboutaud
Copy link
Author

As a fix, I am currently bypassing the SSL verification with verify=False when instantiating the client in as_client = httpx.AsyncClient(), but I am not sure if that's the right permanent solution

@mxrch
Copy link
Owner

mxrch commented Dec 29, 2022

Hi, the problem is related to your environment. Maybe you have a proxy, VPN, or anything else ?

@mxrch mxrch added the help wanted Extra attention is needed label Dec 29, 2022
@sealldeveloper
Copy link

Perhaps also on a restricted network, such as a public WiFi, job/school/university, or anything else.

The error comes from SSL not being verified, so its a client side issue from what I am aware.

@mxrch mxrch closed this as completed Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants