davesteele / gnome-gmail

Integrate GMail into the Linux Desktop
https://davesteele.github.io/gnome-gmail/
GNU General Public License v2.0
50 stars 13 forks source link

Add support for Python 3.4+ #10

Closed scop closed 8 years ago

scop commented 8 years ago

Tested with 2.7.10 and 3.4.3 on Fedora 23, works with both as far as I can tell.

3.[0123] is not supported because POSTing data with urllib demands bytes and msg.as_bytes() exists only in 3.4+, and I don't have access to nor I care about earlier 3.x versions :)

davesteele commented 8 years ago

I reverted this commit. git-bisect traced an HTTP 400 error in (at least) get_access_from_refresh() to this.

scop commented 8 years ago

Could you provide more details? Everything I've tested -- including get_access_from_refresh() -- works fine for me with both Python 2.7.10 and 3.4.3 with these changes in on Fedora 23, no 400's observed.

davesteele commented 8 years ago

It was from the url fetch in get_access_from_refresh(). I reinstalled, but didn't do anything to flush the keyring, so the refresh token should have been valid. I played with encoding, with no effect. Running the code from the commit before the Python 3 work succeeded.

scop commented 8 years ago

I can try to reproduce, but I'm afraid it will be hard. Can you walk me through the exact steps starting from a completely clean setup (including how to clean up all existing tokens)?

If you still have the setup where this happens for you, perhaps you could just check if there's any difference in the urlencoded args POSTed before and after the change? And if there are no obvious changes, check differences in the actual requests with wireshark (that'll require changing token_endpoint to something non-https though, but just POSTing it somewhere unsecured where you don't mind sending that request's content would provide for the capture).

scop commented 8 years ago

Also, with the original python 2 code you can get some debugging output of which the request contents are most interesting with:

import httplib
httplib.HTTPConnection.debuglevel = 1

And in the Python 3 (well, six) version:

from six.moves import http_client
http_client.HTTPConnection.debuglevel = 1
davesteele commented 8 years ago

$ git checkout 06eb3373cc7996a408eb8933283ef4d7a512303a

Remove GNOME GMail connection from your GMail account.

$ ./gnomegmail.py mailto:joe@example.com?attach=/etc/resolv.conf ... File "./gnomegmail.py", line 820, in main() File "./gnomegmail.py", line 805, in main gmailurl = gm_url.gmail_url() File "./gnomegmail.py", line 548, in gmail_url gmailurl = self.api_gmail_url() File "./gnomegmail.py", line 526, in api_gmail_url self.from_address): File "./gnomegmail.py", line 242, in access_iter yield (self.get_access_from_refresh(refresh), refresh) File "./gnomegmail.py", line 208, in get_access_from_refresh urllib.parse.urlencode(args)) File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "/usr/lib/python2.7/urllib2.py", line 437, in open response = meth(req, response) File "/usr/lib/python2.7/urllib2.py", line 550, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.7/urllib2.py", line 475, in error return self._call_chain(_args) File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain result = func(_args) File "/usr/lib/python2.7/urllib2.py", line 558, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 400: Bad Request

scop commented 8 years ago

Ok, got it. The problem is that Google actually does send an HTTP 400 response to indicate that the token has been revoked, and whereas the old urllib passes it happily through, urllib2 doesn't but raises and error instead. #22 takes care of this.