我正在尝试使用他们的核心 API 在 Zendesk 中创建新组织。我已经能够毫无问题地拨打其他电话,但这个电话仍然失败。下面的代码演示了这个问题:
url = "https://mydomain.zendesk.com/api/v2/organizations.json"
new_org = {"organization": {"name": "new organization"}}
data = urllib.urlencode(new_org)
req = urllib2.Request(url,data)
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_manager.add_password(None, url, 'me@email.com', 'fakepassword')
auth_manager = urllib2.HTTPBasicAuthHandler(password_manager)
opener = urllib2.build_opener(auth_manager)
urllib2.install_opener(opener)
response = urllib2.urlopen(req)
bla = response.read()
出现以下错误:
Traceback (most recent call last):
File "/network/nfshome0/homestore00/me/workspace/Pythony/pythony/test2.py", line 35, in <module>
response = urllib2.urlopen(req)
File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 406, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 519, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 438, in error
result = self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 890, in http_error_401
url, req, headers)
File "/usr/lib/python2.7/urllib2.py", line 865, in http_error_auth_reqed
response = self.retry_http_basic_auth(host, req, realm)
File "/usr/lib/python2.7/urllib2.py", line 878, in retry_http_basic_auth
return self.parent.open(req, timeout=req.timeout)
File "/usr/lib/python2.7/urllib2.py", line 406, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 519, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 444, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 527, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
任何帮助将不胜感激!谢谢。