Skip to content

Instantly share code, notes, and snippets.

@hugovk
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugovk/4db84a3bb98416033116 to your computer and use it in GitHub Desktop.
Save hugovk/4db84a3bb98416033116 to your computer and use it in GitHub Desktop.
Attempt to download another user's Wordnik list
#!/usr/bin/env python
# encoding: utf-8
from wordnik import swagger, AccountApi, WordListApi
WORDNIK_USERNAME = TODO
WORDNIK_PASSWORD = TODO
WORDNIK_API_KEY = TODO
permalink = "gapeseeds-and-muckworms---compound-derogatives"
# Prep API
wordnik_client = swagger.ApiClient(WORDNIK_API_KEY,
'http://api.wordnik.com/v4')
wordlist_api = WordListApi.WordListApi(wordnik_client)
# Get token
account_api = AccountApi.AccountApi(wordnik_client)
token = account_api.authenticate(WORDNIK_USERNAME, WORDNIK_PASSWORD).token
# Get list
results = wordlist_api.getWordListWords(permalink, token)
for result in results:
print(result.word)
# End of file
M:\bin>python minitest.py
Traceback (most recent call last):
File "minitest.py", line 22, in <module>
results = wordlist_api.getWordListWords(permalink, token)
File "C:\Python27\lib\site-packages\wordnik\WordListApi.py", line 242, in getWordListWords
postData, headerParams)
File "C:\Python27\lib\site-packages\wordnik\swagger.py", line 71, in callAPI
response = urllib2.urlopen(request)
File "C:\Python27\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 437, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 550, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 475, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 409, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 558, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: Forbidden
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment