Search

Using API in Python - newbie

Subscribe to Using API in Python - newbie 4 post(s)

 
Phoebe Bright

Based on example from the only script I could find online, I have been implementing an interface to unfuddle but am getting a forbidden 403 error. Am a bit of a novice at this so any suggestions very welcome.

Here is the code:

import httplib, base64

auth = base64.encodestring(“%s:%s” % (username, pw)).strip()
print auth

headers = {
“Accept”: “application/xml”,
“Content-Type”: “application/xml”,
“Authorization” : “Basic %s” % auth}

conn = httplib.HTTPSConnection(“tinycomms.unfuddle.com”)
print ‘connection:’,conn.dict

conn.request(“GET”, “/api/v1/projects/1/ticket_reports”)
response = conn.getresponse()
print response.dict
print response.status, response.reason

conn.close

And the output:

connection: {’_buffer’: [], ‘_HTTPConnection__state’: ‘Idle’, ‘cert_file’: None, ‘sock’: None, ‘port’: 443, ‘host’: ‘tinycomms.unfuddle.com’, ‘key_file’: None, ‘_HTTPConnection__response’: None, ‘_method’: None}

{’fp’: , ‘status’: 403, ‘will_close’: False, ‘chunk_left’: ‘UNKNOWN’, ‘length’: 1, ‘strict’: 0, ‘reason’: ‘Forbidden’, ‘version’: 11, ‘debuglevel’: 0, ‘msg’: , ‘chunked’: 0, ‘_method’: ’GET’}

403 Forbidden

 
Joshua Frappier

Phoebe,

I am not very familiar with PHP, however, one of our customers did provide an example using libcurl instead of httplib. The example can be found in the Unfuddle API documentation, here:

http://unfuddle.com/docs/api/code_examples#php

I hope that helps!

 
Phoebe Bright

Still playing around with trying to access unfuddle from PYTHON.

This is the current code that still says ‘Forbidden 403’

import httplib, base64, urllib2 url = “%s://%s.unfuddle.com/api/v1/%s” % (‘https’, ‘tinycomms’, ‘projects’) auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password(realm=‘Unfuddle API’, uri=url, user=settings[‘username’], passwd=settings[‘password’]) opener = urllib2.build_opener(auth_handler) opener.addheaders = [ (‘Content-Type’, ‘application/xml’), (‘Accept’, ‘application/json’) ] try: response = opener.open(url).read().strip() print ‘response:’,response except IOError, e: print IOError, e

Will have to give up and try another ticketing system if I can’t sort it soon – but it must be something obvious???

Apologies for code running together – tried editing it and can’t get line breaks in. Not having a good day…

 
David C.

Phoebe,

It looks like you may be receiving the 403 Forbidden error because you are attempting to access your account using SSL when it does not support SSL. Try using just ‘http’ in your example rather than ‘https’ and see if that works for you.