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

Failed to connect to WakaTime, API Key or endpoint URL invalid ? #514

Closed
thomasbnt opened this issue Aug 16, 2023 · 12 comments
Closed

Failed to connect to WakaTime, API Key or endpoint URL invalid ? #514

thomasbnt opened this issue Aug 16, 2023 · 12 comments

Comments

@thomasbnt
Copy link

Describe the bug
Hello, I would like connect my Wakatime account to Wakapi from https://wakapi.dev/settings#integrations, but when I submit the form, I've this error:

Error: Failed to connect to wakatime, api key or endpoint url invalid?

System information
Wakapi version : v2.8.1-a9364e3 @ mysql
On https://wakapi.dev/

@muety
Copy link
Owner

muety commented Aug 16, 2023

What did you put as the API url and did you make sure your WakaTime key is valid?

@thomasbnt
Copy link
Author

What did you put as the API url and did you make sure your WakaTime key is valid?

Yes of course, for testing another key, I regenerated an another.

@muety
Copy link
Owner

muety commented Aug 16, 2023

What did you put as the API url?

@thomasbnt
Copy link
Author

What did you put as the API url?

This one https://wakatime.com/api/v1

@muety
Copy link
Owner

muety commented Aug 16, 2023

I added some more detailed logging. Please try again and I'll check the server logs afterwards.

@thomasbnt
Copy link
Author

Owww... I just tested with my WakaTime classic key, and not from https://wakatime.com/developers#authentication

You can connect Wakapi with the official WakaTime (or another Wakapi instance, when optionally specifying a custom API URL) in a way that all heartbeats sent to Wakapi are relayed. This way, you can use both services at the same time. To get started, get your API key and paste it here.

All are imported correctly!

@ecker00
Copy link

ecker00 commented Mar 11, 2024

I also got this issue on a self-hosted instance (Using HTTP and accessing via IPs, not public domain). When I run your suggestion above in console I get this:

 ~ curl https://wakatime.com/api/v1/users/current/data_dumps -H "Authorization: Basic $(echo 'waka_xxx' | base64)"

{"data": [{"id": "xxx", "type": "heartbeats", "download_url": "https://wakatime.s3.amazonaws.com/coding-activity-exports/xxx/wakatime-xxx.json?AWSAccessKeyId=xxx&Signature=xxx%3D&Expires=1710753747", "status": "Completed", "percent_complete": 100.0, "expires": "2024-03-18T09:20:24Z", "created_at": "2024-03-11T08:46:40Z", "is_processing": false, "has_failed": false, "is_stuck": false}], "total": 1, "total_pages": 1}%    

I have got a valid JSON download from Wakatime's page, but not sure how to use it (is it possible?). When I enter my details in settings / integrations page, I am stuck on Error: Failed to connect to wakatime, api key or endpoint url invalid?. I notice the server logs show that the request is taking 10.009 seconds, so I guess it's timing out? The curl command responds in about a second or so running on the server.

wakapi  | 2024-03-11T21:12:27.871698498Z [INFO ] [request] status=400, method=POST, uri=/settings, duration=10.009982447s, bytes=48332, addr=172.16.3.9:37392, user=xxx

I've tried various variations of inputs and legacy mode https://wakatime.com/api/v1/ and my api key, also re-generated my API key, but no luck. How can I get my data imported?

@muety
Copy link
Owner

muety commented Mar 11, 2024

Super weird! It's probably the same issue as in #602 (comment), where we also had the problem that requests from cURL or a browser went fine, but timed out in Go. The workaround described in that comment would probably work here as well. But I'd rather want to find the root cause of the problem and reveal why it only occurs for some users (and not on wakapi.dev, for instance).

Can you please try https://api.wakatime.com/api/v1 instead of https://wakatime.com/api/v1 as the API URL (even though I don't think that's gonna change anything)?

Also, what Go- and Wakapi versions are you using and which OS are you on? Do you have both IPv4 and IPv6 available with your ISP or only one or the other?

@ecker00
Copy link

ecker00 commented Mar 12, 2024

Tried both URLs, same result. Using Debian, running in Docker. ISP got both IPv4 and IPv6 here. Version of Wakapi is latest, recently pulled, this is my first time setting up.

Building on your hunch, I went inside the docker container and tried to run the command from there... and no response! (using wget instead of curl, as curl/apt is not available inside the container)

docker compose exec -it wakapi /bin/sh;
$ wget -O- --header="Authorization: Basic $(echo -n 'waka_xxx' | base64)" https://wakatime.com/api/v1/users/current/data_dumps
Connecting to wakatime.com (143.198.244.187:443)
# And it just hangs.... forever 👻

So blaming this one on the container/docker! Then I switched the network mode in docker-compose from port: 3000:3000 to network_mode: host to see if it would be able to connect, and yes it does!

docker compose exec -it wakapi /bin/sh;
$ wget -O- --header="Authorization: Basic $(echo -n 'waka_xxx' | base64)" https://wakatime.com/api/v1/users/current/data_dumps
Connecting to wakatime.com ([2604:a880:4:1d0::fd:3000]:443)

writing to stdout
-                    100% |***************************************************************************************************************************************|    42  0:00:00 ETA
written to stdout

Also looks like it switched to using IPv6 to connect now, first time it attempted over IPv4? An odd but maybe inconsequential observation. Alright, at least it works, but not optimal to run this way. So I'm switching back to port mode and turning off host-mode, to test some more:

# Can we connect to the internet? Yes:
docker compose exec -it wakapi /bin/sh;
$ wget -O- http://httpbin.org/get
Connecting to httpbin.org (107.21.176.221:80)
writing to stdout
{
  "args": {}, 
  "headers": {
    "Host": "httpbin.org", 
    "User-Agent": "Wget", 
    "X-Amzn-Trace-Id": "Root=1-65f0b048-5ce731233c15cf02723fce25"
  }, 
  "origin": "81.167.234.40", 
  "url": "http://httpbin.org/get"
}
-                    100% |**************************************************************|   225  0:00:00 ETA
written to stdout

# Ok some more IP testing, can we do IPv6?
$ wget -qO- http://ipv6-test.com/api/myip.php
81.167.000.000
# No, that's certainly an IPv4 address, outside the container it returns as IPv6

Alright so maybe you're hunch about IPv4 / IPv6 is correct. Building on that theory, outside the container I force WakaTime API to query via IPv4:

$ wget -O- -4 https://api.wakatime.com/api/v1/meta
--2024-03-12 21:00:42--  https://api.wakatime.com/api/v1/meta
Resolving api.wakatime.com (api.wakatime.com)... 143.244.210.202
Connecting to api.wakatime.com (api.wakatime.com)|143.244.210.202|:443... connected.
<NOTHING>

And nothing, no response! Remove the -4 flag and the API works again. So I try the same query to WakaTime API over IPv4 on my local machine and it work! ... wait what?

My conclusion so far:

  • The Wakapi docker container got an issue with IPv6 in general
  • Wakatime API confimed works fine with both IPv4/IPv6
  • My server has an issue dealing with IPv4 with WakaTime specifically

I do not comprehend why I cant query Wakatime API on some of my VMs via IPv4, one thing those VMs have in common is using Proxmox 8 SDN, but I am not seeing issues with other IPv4 services. What should maybe be investigated is making IPv6 work inside the container?

@muety
Copy link
Owner

muety commented Mar 12, 2024

Wow, thanks a lot for your detailed investigations!

The Wakapi docker container got an issue with IPv6 in general

Last time I checked, Docker didn't even support IPv6 whatsoever, so curl / wget shouldn't ever even attempt to connect via v6. But apparently either I was wrong or things have changed meanwhile, see Enable IPv6 support.

But still, could you please check if (a) your container actually has an IPv6 and (b) you can force curl to use v6 (-6) and then try request some other host (like https://6.ipwho.de/ip) again?

Please also try different combinations of IPv4 vs. IPv6, inside vs. outside container and with vs. without --no-keepalive (as the connection reuse had been problematic in the issue I linked above).

@ecker00
Copy link

ecker00 commented Mar 12, 2024

I've tried "everything", only ting I can pinpoint is that my IPv6 handling in a certain subnet I got is not working reliably. And it seems that the IPv4 connection to WakaAPI also is struggling in that subnet.

# Both of these queries either fail or work (at least on my weird network)
wget -qO- -6 https://6.ipwho.de/ip
wget -qO- -4 https://api.wakatime.com/api/v1/meta

Thanks for your help, seems like this is a me problem and not a Wakapi problem.

@muety
Copy link
Owner

muety commented Mar 13, 2024

Keep me posted, would love to learn how you got this fixed in the end! Also, let me know if I can provide further help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants