httplib2 Http 클래스를 사용하여 Twilio에 대한 API 요청을 만들려고했는데 요청을 설정하는 방법에 상관없이 내 게시물 데이터를 보내지 않습니다. 로컬 URL에 게시하고 게시물 인수가 비어 있기 때문에 이것을 알고 있습니다. 여기 내 코드입니다 :Python httplib2.Http 게시 매개 변수를 보내지 않습니다.
_TWILIO_URL = 'https://api.twilio.com/2010-04-01/Accounts/%s/%s'
class Api(object):
'''
A Python interface to the Twilio API
'''
def __init__(self, AccountSid, AuthToken, From):
self.AccountSid = AccountSid
self.AuthToken = AuthToken
self.From = From
def _get_from(self, From):
"""Use the provided From number or the one defined on initialization"""
if From:
return From
else:
return self.From
def call(self, To, Url, From=None):
"""Sends a request to Twilio having it call a number; the provided URL will indicate how to handle the call"""
url = _TWILIO_URL % (self.AccountSid, 'Calls')
data = dict(From=self._get_from(From), To=To, Url=Url)
return self.request(url, body=urlencode(data))
def request(self, url, method='POST', body=None, headers={'content-type':'text/plain'}):
"""Send the actual request"""
h = Http()
h.add_credentials(self.AccountSid, self.AuthToken)
resp, content = h.request(url, method=method, body=body, headers=headers)
print content
if resp['status'] == '200':
return loads(content)
else:
raise TwilioError(resp['status'], content)
def sms(self, To, Body, From=None):
"""Sends a request to Twilio having it call a number; the provided URL will indicate how to handle the call"""
url = _TWILIO_URL % (self.AccountSid, 'SMS/Messages')
data = dict(From=self._get_from(From), To=To, Body=Body)
return self.request(url, body=urlencode(data))
나는 문제 해결에 대해 이야기 구글에 아무것도 찾을 수 없습니다
콘텐츠 유형이 IS이기 때문입니다. POST 요청 (HTML 양식에서 사용될 때)에 대한 가장 분명한 내용 유형이긴하지만 POST는 html, xml, pdf 등과 같은 다른 내용에도 사용될 수 있으며 심지어 html 양식은 이 유형 (http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4 참조). 이 방법을보십시오 : 당신은 "파일"을 올리며 어떤 유형인지 선언해야합니다. – Steven