Running Auto-Tag from Algorithmia

301 Views Asked by At

I'm trying to run Auto-Tag from Algorithmia, and mainly tried with cURL and Pyhton, and get an error that states:

cURL

{"error":{"message":"authorization required"}}

Python

Last login: Mon Jul  6 20:27:54 on ttys000
cd '/Users/abc/Desktop/' && '/usr/bin/pythonw'  '/Users/abc/Desktop/autoTag.py'  && echo Exit status: $? && exit 1
abc-MacBook-Pro:~ abc$ cd '/Users/abc/Desktop/' && '/usr/bin/pythonw'  '/Users/abc/Desktop/autoTag.py'  && echo Exit status: $? && exit 1
Traceback (most recent call last):
  File "/Users/abc/Desktop/autoTag.py", line 6, in <module>
    response = urllib2.urlopen(request, json.dumps(input))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 410, in open
    response = meth(req, response)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 523, in http_response
    'http', request, response, code, msg, hdrs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 448, in error
    return self._call_chain(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 531, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Unauthorized

What am I doing wrong?

Thanks.

2

There are 2 best solutions below

0
On

According to the documentation for AutoTag, you'll want to include authorization information as a header on your request before sending it.

Here's their example:

import urllib2, json
input = ["rails","rails"]
request = urllib2.Request('https://api.algorithmia.com/v1/algo/tags/AutoTagGithub/0.1.1')
request.add_header('Content-Type', 'application/json')
request.add_header('Authorization', 'Simple sim11111111111111111123456789abcdef')
response = urllib2.urlopen(request, json.dumps(input))
print response.read()

If you're following their example (as it looks like you are), I'd recommend putting your own token in in place of sim11111111111111111123456789abcdef.

0
On

The Algorithmia python client available on PyPi allows setting the API Key directly:

import Algorithmia

input = ["rails","rails"]
client = Algorithmia.client('YOUR_API_KEY')
algo = client.algo('tags/AutoTagGithub/0.1.4')
print algo.pipe(input)