linux-cli icon indicating copy to clipboard operation
linux-cli copied to clipboard

An error occured while attempting to reach API

Open blackPantherOS opened this issue 4 years ago • 41 comments

Hi,

We got this message after tried login and enter password


Enter your ProtonVPN password: 

An error occured while attempting to reach API

The log

cat protonvpn-cli.log

2021-06-16 22:01:03,580 — cli.py — INFO — __init__:49 — 
-------------------------------------------------

-----------     Initialized protonvpn-cli       -----------

-------------------------------------------------
2021-06-16 22:01:03,580 — cli.py — INFO — __init__:54 — ProtonVPN CLI v3.6.0 (protonvpn-nm-lib v3.2.1; proton-client v0.5.1)
2021-06-16 22:01:03,580 — cli.py — INFO — __init__:57 — CLI command: Namespace(command='login', help=False, version=False)
2021-06-16 22:01:08,328 — cli_wrapper.py — INFO — login:68 — Credentials provided, attempting to login
2021-06-16 22:01:08,350 — cli_wrapper.py — ERROR — login:73 — An error occured while attempting to reach API
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/requests/models.py", line 382, in prepare_url
    scheme, auth, host, port, path, query, fragment = parse_url(url)
  File "/usr/lib/python3.7/site-packages/urllib3/util/url.py", line 392, in parse_url
    return six.raise_from(LocationParseError(source_url), None)
  File "<string>", line 3, in raise_from
urllib3.exceptions.LocationParseError: Failed to parse: https://api.protonvpn.ch/auth/info

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/proton/api.py", line 103, in api_request
    timeout=self.__timeout
  File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 590, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 528, in request
    prep = self.prepare_request(req)
  File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 466, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/lib/python3.7/site-packages/requests/models.py", line 316, in prepare
    self.prepare_url(url, params)
  File "/usr/lib/python3.7/site-packages/requests/models.py", line 384, in prepare_url
    raise InvalidURL(*e.args)
requests.exceptions.InvalidURL: Failed to parse: https://api.protonvpn.ch/auth/info

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/protonvpn_nm_lib/core/session/session.py", line 26, in __call__
    result = self._func(session, *args, **kwargs)
  File "/usr/lib/python3.7/site-packages/protonvpn_nm_lib/core/session/session.py", line 294, in authenticate
    self.__proton_api.authenticate(username, password)
  File "/usr/lib/python3.7/site-packages/proton/api.py", line 146, in authenticate
    info_response = self.api_request("/auth/info", payload)
  File "/usr/lib/python3.7/site-packages/proton/api.py", line 112, in api_request
    raise UnknownConnectionError(e)
proton.exceptions.UnknownConnectionError: Failed to parse: https://api.protonvpn.ch/auth/info

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/protonvpn_cli/cli_wrapper.py", line 71, in login
    self.protonvpn.login(username, password)
  File "/usr/lib/python3.7/site-packages/protonvpn_nm_lib/api.py", line 28, in login
    self._env.api_session.authenticate(username, password)
  File "/usr/lib/python3.7/site-packages/protonvpn_nm_lib/core/session/session.py", line 44, in __call__
    raise APIError("An error occured while attempting to reach API")
protonvpn_nm_lib.exceptions.APIError: An error occured while attempting to reach API

blackPantherOS avatar Jun 16 '21 19:06 blackPantherOS

The same here. been like this for about a month now. I've had this issue before with the previous protonvpn command lines. probably has to do with protonvpn being blocked in my country [Iran].

lennyfrost avatar Jun 17 '21 14:06 lennyfrost

Hey @blackPantherOS

Can you ping api.protonvpn.ch ? If not then is indeed as @lennyalderson is stating. We're currently working on alternative routing, so this shouldn't be happening once alternative routing is complete.

calexandru2018 avatar Jun 23 '21 07:06 calexandru2018

when alternative routing will be available? protonvpn-cli-ng app told me to upgrade to 3.7.1 version of protonvpn-cli and now I can't change from protonvpn.ch to protonmail.ch!

OS: Manjaro Kde ornara 21.0.7

pmoieni avatar Jul 04 '21 18:07 pmoieni

I have same problem

ghonchesefidi avatar Sep 15 '21 19:09 ghonchesefidi

I have same problem

It's about 3 months I posted my comment and they didn't add the alternative routing. It's available on their mobile app but takes time to migrate it to Linux. At the moment you'd rather use protonvpn-cli-ng from AUR if you are using arch. It's still maintained and works fine. I'm in Iran BTW😁

pmoieni avatar Sep 15 '21 20:09 pmoieni

Hey @Graham1384 , @ghonchesefidi , @lennyfrost and @blackPantherOS . Alternative routing is now available in early access. If you would like to try it out, select your distro from here and follow the steps to install early access (aka beta) version.

Please provide some feedback here or (preferably) to our support.

Edit: Since it's still in early access, there is no support for arch based systems.

calexandru2018 avatar Sep 16 '21 16:09 calexandru2018

@calexandru2018 Thanks for your update. I have followed the link and was able to install the beta version and it's working fine for me now. Appreciate your help.

ghonchesefidi avatar Sep 17 '21 07:09 ghonchesefidi

Alternative routing has been pushed to stable branch, and that includes AUR. Please provide feedback if alternative routing did work, and if so close this issue.

calexandru2018 avatar Sep 23 '21 16:09 calexandru2018

Alternative routing has been pushed to stable branch, and that includes AUR. Please provide feedback if alternative routing did work, and if so close this issue.

thanks, It's working now on Manjaro. really faster than the ng version.

pmoieni avatar Sep 24 '21 08:09 pmoieni

I had to test it more precisely. when I try to log in via wifi. I get this message: HTTPSConnectionPool(host='dns11.quad9.net', port=443): Read timed out. (read timeout=3.05)

config says it's enabled:

ProtonVPN User Settings

Default Protocol: OpenVPN (UDP) Kill Switch: Off Netshield: Disabled DNS: Automatic Alternative Routing: Enabled VPN Accelerator: Enabled

as far as I know, the mobile version first will establish a connection to log in user and then receives servers. I'm not a professional programmer but it seems the list of the servers is saved in a file that is accessible offline.

It's not a big deal for me as long as I can log in just one time with mobile data and then everything works.

pmoieni avatar Sep 24 '21 09:09 pmoieni

@Graham1384 can you reach out to support ?

So login works from mobile data but not wifi ?

calexandru2018 avatar Sep 24 '21 09:09 calexandru2018

@Graham1384 can you reach out to support ?

So login works from mobile data but not wifi ?

yes

another alternative routing for login I think.

pmoieni avatar Sep 24 '21 09:09 pmoieni

@Graham1384 can you reach out to support ?

So login works from mobile data but not wifi ?

after restarting the laptop the connection itself won't work. it gets stuck here:

image

first I have to connect with mobile data to receive servers then I can connect with wifi

pmoieni avatar Sep 24 '21 12:09 pmoieni

@calexandru2018 should I install the community version or a fix will be available soon?

pmoieni avatar Sep 25 '21 12:09 pmoieni

@Graham1384 please contact support as we need to debug and understand what is happening.

calexandru2018 avatar Sep 25 '21 14:09 calexandru2018

@Graham1384 @calexandru2018 I have the same problem , I'm running on manjaro I used aur packages, but when I try to login , I encounter an error: HTTPSConnectionPool(host='dns11.quad9.net', port=443): Read timed out. (read timeout=3.05)

I checked the log files: 2021-10-09 15:46:12,931 — cli.py — INFO — init:29 — ProtonVPN CLI v3.9.1 (protonvpn-nm-lib v3.4.1; proton-client v0.6.1) 2021-10-09 15:46:12,933 — cli.py — INFO — init:64 — CLI command: Namespace(command='login', version=False, help=False, get_logs=False) 2021-10-09 15:46:14,479 — cli_wrapper.py — INFO — login:68 — Credentials provided, attempting to login 2021-10-09 15:46:46,338 — cli_wrapper.py — INFO — login:68 — Credentials provided, attempting to login 2021-10-09 15:47:14,562 — cli_wrapper.py — ERROR — login:80 — HTTPSConnectionPool(host='dns11.quad9.net', port=443): Read timed out. (read timeout=3.05) Traceback (most recent call last): File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 382, in _make_request self._validate_conn(conn) File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1010, in validate_conn conn.connect() File "/usr/lib/python3.9/site-packages/urllib3/connection.py", line 411, in connect self.sock = ssl_wrap_socket( File "/usr/lib/python3.9/site-packages/urllib3/util/ssl.py", line 449, in ssl_wrap_socket ssl_sock = ssl_wrap_socket_impl( File "/usr/lib/python3.9/site-packages/urllib3/util/ssl.py", line 493, in _ssl_wrap_socket_impl return ssl_context.wrap_socket(sock, server_hostname=server_hostname) File "/usr/lib/python3.9/ssl.py", line 500, in wrap_socket return self.sslsocket_class._create( File "/usr/lib/python3.9/ssl.py", line 1040, in _create self.do_handshake() File "/usr/lib/python3.9/ssl.py", line 1309, in do_handshake self._sslobj.do_handshake() socket.timeout: _ssl.c:1112: The handshake operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3.9/site-packages/requests/adapters.py", line 439, in send resp = conn.urlopen( File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen retries = retries.increment( File "/usr/lib/python3.9/site-packages/urllib3/util/retry.py", line 532, in increment raise six.reraise(type(error), error, _stacktrace) File "/usr/lib/python3.9/site-packages/urllib3/packages/six.py", line 770, in reraise raise value File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 699, in urlopen httplib_response = self._make_request( File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 385, in _make_request self._raise_timeout(err=e, url=url, timeout_value=conn.timeout) File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 336, in _raise_timeout raise ReadTimeoutError( urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='dns11.quad9.net', port=443): Read timed out. (read timeout=3.05)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3.9/site-packages/protonvpn_cli/cli_wrapper.py", line 71, in login self.protonvpn.login(username, password) File "/usr/lib/python3.9/site-packages/protonvpn_nm_lib/api.py", line 30, in login self._env.api_session.authenticate(username, password) File "/usr/lib/python3.9/site-packages/protonvpn_nm_lib/core/session/session.py", line 34, in call result = self._func(session, *args, **kwargs) File "/usr/lib/python3.9/site-packages/protonvpn_nm_lib/core/session/session.py", line 359, in authenticate self.__proton_api.authenticate(username, password) File "/usr/lib/python3.9/site-packages/proton/api.py", line 366, in authenticate info_response = self.api_request("/auth/info", payload) File "/usr/lib/python3.9/site-packages/proton/api.py", line 262, in api_request response = self.__try_with_alt_routing(fct, **request_params) File "/usr/lib/python3.9/site-packages/proton/api.py", line 282, in __try_with_alt_routing alternative_routes = self.get_alternative_routes_from_dns() File "/usr/lib/python3.9/site-packages/proton/api.py", line 494, in get_alternative_routes_from_dns dns_hosts_response = list( File "/usr/lib/python3.9/concurrent/futures/_base.py", line 610, in result_iterator yield fs.pop().result(end_time - time.monotonic()) File "/usr/lib/python3.9/concurrent/futures/_base.py", line 445, in result return self.__get_result() File "/usr/lib/python3.9/concurrent/futures/_base.py", line 390, in __get_result raise self._exception File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run result = self.fn(*self.args, **self.kwargs) File "/usr/lib/python3.9/site-packages/proton/api.py", line 548, in __query_for_dns_data response = requests.get( File "/usr/lib/python3.9/site-packages/requests/api.py", line 75, in get return request('get', url, params=params, **kwargs) File "/usr/lib/python3.9/site-packages/requests/api.py", line 61, in request return session.request(method=method, url=url, **kwargs) File "/usr/lib/python3.9/site-packages/requests/sessions.py", line 542, in request resp = self.send(prep, **send_kwargs) File "/usr/lib/python3.9/site-packages/requests/sessions.py", line 655, in send r = adapter.send(request, **kwargs) File "/usr/lib/python3.9/site-packages/requests/adapters.py", line 529, in send raise ReadTimeout(e, request=request) requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='dns11.quad9.net', port=443): Read timed out. (read timeout=3.05) 2021-10-09 15:51:02,767 — cli.py — INFO — init:17 —

my config file is look like: { "default_protocol": "udp", "killswitch": 0, "dns": { "dns_status": 2, "custom_dns": [ "1.1.1.1" ] }, "split_tunneling": { "split_tunneling_status": 0, "ip_list": [] }, "netshield": 0, "secure_core": 0, "vpn_accelerator": 1, "alternative_routing": 1 }

I'm not sure 100 percent but I think there's something wrong with alternative routes after I'd tried to to turn off alternative_routing , I encountered this error: Unable to reach API

I changed the default dns to 1.1.1.1/ 8.8.8.8 but still not working!

I can confidently ping dns11.quad9.net and that's working . I tried to test the dns11.quad9.net with https commmand line tool for dns11.quad9.net: With out vpn connection that wasn't reachable after setup vpn connection with legacy protonvpn that was perfectly fine and that was reachable.

I think the problem is dns11.quad9.net. Hope that receive fixed version soon.

aliazani avatar Oct 09 '21 16:10 aliazani

@aliazani try enable dns to automatic and enable alt routing

calexandru2018 avatar Oct 09 '21 16:10 calexandru2018

@calexandru2018 I did that too but not still not working! I got HTTPSConnectionPool(host='dns11.quad9.net', port=443): Read timed out. (read timeout=3.05)

aliazani avatar Oct 09 '21 16:10 aliazani

@aliazani please reach out to support

calexandru2018 avatar Oct 09 '21 16:10 calexandru2018

@calexandru2018 when I was using protonvpn-cli-ng package I always had to change its python code before logging in. I always change "protonvpn.ch" to "protonmail.ch". can it be related to this issue? because in my country protonvpn.ch is blocked and only protonmail.ch works.

pmoieni avatar Oct 10 '21 22:10 pmoieni

@calexandru2018 @aliazani

I think I've found a workaround by accident

  1. first change dns to 1.1.1.1
  2. then connect to mobile hotspot. (one that can ping protonvpn.ch)
  3. now login to your account using cli
  4. then connect to any network you want and connect to VPN

It worked for me. try it out!

pmoieni avatar Oct 10 '21 23:10 pmoieni

@Graham1384 with alt routing this shouldn't be necessary. If alt routing is not working for you, please reach out to customer support so we can gather more info and make sure that alternative routing is working for you (and others that are in a similar situation)

calexandru2018 avatar Oct 10 '21 23:10 calexandru2018

@calexandru2018 I sent a post to support an hour ago. waiting for the answer.

pmoieni avatar Oct 10 '21 23:10 pmoieni

@calexandru2018 @aliazani

I think I've found a workaround by accident

1. first change dns to 1.1.1.1

2. then connect to mobile hotspot. (one that can ping protonvpn.ch)

3. now login to your account using cli

4. then connect to any network you want and connect to VPN

It worked for me. try it out!

seems this is not permanent. after some specific amount of time, it gets stuck on the blue screen.

when I try using the fastest server it works. protonvpn-cli c -f

but choosing server from menu gets stuck on the blue screen.

pmoieni avatar Oct 11 '21 04:10 pmoieni

I sent a ticket to support and hope that they find a solution

aliazani avatar Oct 11 '21 17:10 aliazani

Hey @aliazani and @Graham1384 , the situation was identified and a patch will be pushed next beta release. The issue was that the exception was not being catched, thus not allowing to loop through the available DNSs.

Make sure you have the beta version installed to receive the latest versions and test it out.

calexandru2018 avatar Oct 16 '21 12:10 calexandru2018

Hey @aliazani and @Graham1384 , the situation was identified and a patch will be pushed next beta release. The issue was that the exception was not being catched, thus not allowing to loop through the available DNSs.

Make sure you have the beta version installed to receive the latest versions and test it out.

I contacted support and all they said was that your ISP is blocking our servers and in your country you can't use linux cli because we use some packages that won't let us implement alternative routing as it is on windows and mobile app. I hope it'll work. To be honest Linux really doesn't work without a good VPN.

pmoieni avatar Oct 16 '21 13:10 pmoieni

@calexandru2018 Great, let us know when it was available.

aliazani avatar Oct 16 '21 14:10 aliazani

@aliazani @Graham1384 this has been addressed with the newest version. Indeed a check was not being made for the next in the list DNS to a exception not being handled. This has been now addressed. Please confirm that this solution is working for you.

If both of the dns hosts are blocked there is no way to circumvent it. Here you can find a list of them: https://github.com/ProtonMail/proton-python-client/blob/master/proton/constants.py#L24 (but hopefully you will do to our implementation of encoded urls)

calexandru2018 avatar Oct 25 '21 14:10 calexandru2018

@calexandru2018 Portonvpn-cli log:


2021-10-25 14:45:55,498 — cli.py — INFO — init:64 — CLI command: Namespace(command='login', version=False, help=False, get_logs=False) 2021-10-25 14:45:58,879 — cli_wrapper.py — INFO — login:68 — Credentials provided, attempting to login 2021-10-25 14:46:30,216 — cli_wrapper.py — ERROR — login:117 — Network error Traceback (most recent call last): File "/usr/lib/python3.9/site-packages/protonvpn_cli/cli_wrapper.py", line 73, in login self.protonvpn.login(username, password) File "/usr/lib/python3.9/site-packages/protonvpn_nm_lib/api.py", line 31, in login self._env.api_session.authenticate(username, password, human_verification) File "/usr/lib/python3.9/site-packages/protonvpn_nm_lib/core/session/session.py", line 39, in call result = self._func(session, *args, **kwargs) File "/usr/lib/python3.9/site-packages/protonvpn_nm_lib/core/session/session.py", line 382, in authenticate self.__proton_api.authenticate(username, password) File "/usr/lib/python3.9/site-packages/proton/api.py", line 387, in authenticate info_response = self.api_request("/auth/info", payload) File "/usr/lib/python3.9/site-packages/proton/api.py", line 261, in api_request response = self.__try_with_alt_routing(fct, **request_params) File "/usr/lib/python3.9/site-packages/proton/api.py", line 327, in __try_with_alt_routing raise NetworkError("Network error") proton.exceptions.NetworkError: Network error

aliazani avatar Oct 25 '21 15:10 aliazani