Insightly / insightly-python

Insightly Python SDK
26 stars 32 forks source link

does not work for Python Version: 3.5.1 #27

Open angelapper opened 8 years ago

angelapper commented 8 years ago

Request Method: POST Request URL: http://localhost:8000/course-register-form/ Django Version: 1.8.4 Exception Type: TypeError Exception Value:
POST data should be bytes or an iterable of bytes. It cannot be of type str. Exception Location: C:\Users\angelapper\Anaconda3\envs\datalaushome\lib\urllib\request.py in dorequest, line 1170 Python Executable: C:\Users\angelapper\Anaconda3\envs\datalaushome\python.exe Python Version: 3.5.1

dkingman commented 8 years ago

I can confirm this is an issue. Python 3.5.0

Full stack trace:

  File "/project/insightly.py", line 352, in create
    text = self.generateRequest(url, 'POST', data)
  File "/project/insightly.py", line 593, in generateRequest
    result = urllib2.urlopen(request, data)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 162, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 463, in open
    req = meth(req)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 1170, in do_request_
    raise TypeError(msg)
TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str.
[25/May/2016 15:18:30] "POST /api/registration/ HTTP/1.1" 500 157495

In my case I was calling insightly.create('contacts', contact).

contact = {
  'last_name': 'NA', 
  'first_name': 'NA', 
  'tags': [{'TAG_NAME': 'web_signup'}],
  'CONTACTINFOS': [{'LABEL': 'Work', 'DETAIL': 'test@test.com', 'TYPE': 'EMAIL', 'SUBTYPE': None}]
}
dkingman commented 8 years ago

Any update on this?

subssn21 commented 8 years ago

Easy enough to fix. Add .enocde("utf-8") to data on line 596 of insightly.py, should be backwards compatible with 2.7, but someone with a 2.7 codebase should doublecheck.

18 has the fix in it, I meant to make it a separate pull request, but I didn't have everything in separate branches.