wakatime / sublime-wakatime

Sublime Text 2 & 3 plugin for automatic time tracking and metrics generated from your programming activity.
https://wakatime.com/sublime-text
BSD 3-Clause "New" or "Revised" License
525 stars 47 forks source link

Proxy not working #49

Closed darkvertex closed 7 years ago

darkvertex commented 9 years ago

My package user settings look like this:

{
    "api_key": "mykey",
    "hidefilenames": false,
    "proxy": "http://alan:password@192.168.253.253:3178"
}

and my ~/.wakatime.cfg looks like this:

[settings]
debug = false
hidefilenames = false
proxy = http://alan:password@192.168.253.253:3178
api_key = mykey

I looked at https://wakatime.com/api/v1/users/current while logged in and saw lines:

    "last_heartbeat": null,
    "last_plugin": null,
    "last_plugin_name": null,
    "last_project": null,

so I guess it's not working.

What am I doing wrong?

alanhamlett commented 9 years ago

Let's set debug to true and check $HOME\.wakatime.log for more detailed info. Any hints in there?

darkvertex commented 9 years ago

Sure. Here we go:

{
  "now": "2015/07/07 18:07:42 +0000",
  "version": "4.0.16",
  "plugin": "sublime/3083 sublime-wakatime/4.0.8",
  "time": 1436306797.3847189,
  "caller": "/mnt/users/alan/.config/sublime-text-3/Packages/WakaTime/packages/wakatime/base.py",
  "lineno": 384,
  "isWrite": true,
  "file": "/mnt/users/alan/somefile.py",
  "level": "WARNING",
  "message": {
    "traceback": "Traceback (most recent call last):\n  File \"/mnt/users/alan/.config/sublime-text-3/Packages/WakaTime/packages/wakatime/base.py\", line 373, in send_heartbeat\n    proxies=proxies)\n  File \"/mnt/users/alan/.config/sublime-text-3/Packages/WakaTime/packages/wakatime/packages/requests/sessions.py\", line 507, in post\n    return self.request('POST', url, data=data, json=json, **kwargs)\n  File \"/mnt/users/alan/.config/sublime-text-3/Packages/WakaTime/packages/wakatime/packages/requests/sessions.py\", line 464, in request\n    resp = self.send(prep, **send_kwargs)\n  File \"/mnt/users/alan/.config/sublime-text-3/Packages/WakaTime/packages/wakatime/packages/requests/sessions.py\", line 576, in send\n    r = adapter.send(request, **kwargs)\n  File \"/mnt/users/alan/.config/sublime-text-3/Packages/WakaTime/packages/wakatime/packages/requests/adapters.py\", line 424, in send\n    raise ConnectionError(e, request=request)\nConnectionError: HTTPSConnectionPool(host='wakatime.com', port=443): Max retries exceeded with url: /api/v1/heartbeats (Caused by ProxyError('Cannot connect to proxy.', error(110, 'Connection timed out')))\n",
    "ConnectionError": "HTTPSConnectionPool(host='wakatime.com', port=443): Max retries exceeded with url: /api/v1/heartbeats (Caused by ProxyError('Cannot connect to proxy.', error(110, 'Connection timed out')))"
  }
}

(It was all one line, I added spacing for clarity.)

darkvertex commented 9 years ago

Is there a way to configure it to try without SSL? Maybe my ssl libs are messed up or something.

alanhamlett commented 9 years ago

Does your http proxy support https connections?

alanhamlett commented 9 years ago

You can't disable https, because the wakatime api will reject your api request if it's over http.

darkvertex commented 9 years ago

Yes it does. Or rather, I use it with a web browser (Chromium) at work and I go to https:// links all the time without problems... so I guess it works with https.

alanhamlett commented 9 years ago

Let's try testing the proxy with plain Python and the requests library. WakaTime just does a simple https POST request passing requests the proxy: https://github.com/wakatime/sublime-wakatime/blob/f0b518862a69b478553f4ed4bbe3526a8f0e320b/packages/wakatime/base.py#L354

We can test the proxy setting with python on the command line inside the sublime-wakatime git repo directory:

$ cd sublime-wakatime
$ cd packages
$ python
>>> from wakatime.packages import requests
>>> proxies = {'https': 'https://user:pass@localhost:8000'}
>>> response = requests.get('https://google.com/', proxies=proxies)
>>> print(response.status_code)

Change the proxies until it works. Maybe try adding the proxy to the http key instead of the https key.

darkvertex commented 8 years ago

Hi Alan, Sorry for not testing sooner; this fell through piles of emails. Anyhow, I got your sample working if proxies looks like:

proxies = {
'http': 'http://alan:password@myfirewall:port',
'https': 'http://alan:password@myfirewall:port'
}

Seems as if proxies doesn't have an https entry, it won't go through for any https:// urls and also my firewall proxy itself still needs to go via http even for https sites.

So now knowing this, I should ask... does the ~/.wakatime.cfg "proxy" entry get used for both http and https requests? Is it populating the proxies dict for both http and https keys? If not, that might be the issue.

alanhamlett commented 8 years ago

It only populates the https key of the proxies argument because wakatime only makes requests to https urls, so if your ~/.wakatime.cfg has a line like:

proxy = http://alan:password@myfirewall:port

Then your proxies argument would be generated like:

proxies = {
    'https': 'http://alan:password@myfirewall:port',
}
alanhamlett commented 7 years ago

Fixed in the latest version.