Created
August 22, 2011 16:27
-
-
Save atomicules/1162823 to your computer and use it in GitHub Desktop.
Investigate proxy authentication issues in simplenote.vim. See https://github.com/i5m/simplenote.vim/commit/8d0a0d9a1d7c8edee3efc28cef62936f36b2b4d4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
import urllib2 | |
import base64 | |
import json | |
snuser = "" | |
snpassword = "" | |
proxyurl = "<proxy url>:<proxy port>" | |
proxylogin = "<proxy username>:<proxy password>" | |
#Fetch Simplenote token | |
auth_params = "email=%s&password=%s" % (urllib2.quote(snuser), urllib2.quote(snpassword)) | |
values = base64.encodestring(auth_params) | |
AUTH_URL = 'https://simple-note.appspot.com/api/login' | |
request = urllib2.Request(AUTH_URL, values) | |
#Behind a proxy | |
res = urllib2.urlopen(request).read() | |
#Will fail as expected | |
#Set proxy authentication | |
request.set_proxy(proxyurl, 'http') | |
request.add_header('Proxy-Authorization', 'Basic %s' % base64.b64encode(proxylogin)) | |
#This then works | |
res = urllib2.urlopen(request).read() | |
#Now fetch a list of notes | |
token = res | |
INDX_URL = 'https://simple-note.appspot.com/api2/index?' | |
params = 'auth=%s&email=%s&length=%s' % (token, urllib2.quote(snuser), 20) | |
request = urllib2.Request(INDX_URL+params) | |
request.set_proxy(proxyurl, 'http') | |
request.add_header('Proxy-Authorization', 'Basic %s' % base64.b64encode(proxylogin)) | |
res = json.loads(urllib2.urlopen(request).read()) | |
#This works. Why the hell doesn't it work in Simplenote.vim? | |
#Actually, after further testing this seems to only sporadically work. Perhaps there are issues with the API and/or my proxy? | |
#Sometimes doing this helps, sometimes not: | |
request.set_proxy(proxyurl, 'https') | |
request.set_proxy(proxyurl, 'http') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment