2016-05-17 7 views
0

を私はTwilioためUdacityチュートリアルに続き、次のように私は例外を取得:Twilio - Pythonの例外SMSを送信中 - Udacityチュートリアル

Traceback (most recent call last): 
    File "/Users/kaushiksekar/Documents/Programs/Python/send_text.py", line 10, in <module> 
    from_="+14066234282") # Replace with your Twilio number 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio-6.3.dev0-py2.7.egg/twilio/rest/resources/messages.py", line 122, in create 
    return self.create_instance(kwargs) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio-6.3.dev0-py2.7.egg/twilio/rest/resources/base.py", line 365, in create_instance 
    data=transform_params(body)) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio-6.3.dev0-py2.7.egg/twilio/rest/resources/base.py", line 200, in request 
    resp = make_twilio_request(method, uri, auth=self.auth, **kwargs) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio-6.3.dev0-py2.7.egg/twilio/rest/resources/base.py", line 164, in make_twilio_request 
    uri=resp.url, msg=message, code=code) 
TwilioRestException: 
[31m[49mHTTP Error[0m [37m[49mYour request was:[0m 

[36m[49mPOST https://api.twilio.com/2010-04-01/Accounts/{{ AC142b2a041b9695a2e7d73572cd7989b0 }}/Messages.json[0m 

[37m[49mTwilio returned the following information:[0m 

[34m[49m[0m 

>>> 

コード:どのような問題に

from twilio.rest import TwilioRestClient 

account_sid = "{{ authorization sid copied correctly from the site }}" # Your Account SID from www.twilio.com/console 
auth_token = "{{ authorization token copied correctly from the site }}" # Your Auth Token from www.twilio.com/console 

client = TwilioRestClient(account_sid, auth_token) 

message = client.messages.create(body="Hey this is a Test SMS", 
    to="+919551771607", # Replace with your phone number 
    from_="+14066234282") # Replace with your Twilio number 

print(message.sid) 

任意のポインタをかもしれない?

+0

このエラーの原因となったコードを投稿してください。発生した例外は、TwilioRestExceptionです。これは、ドキュメントによると、 "Twilio APIからの一般的な400または500レベルの例外"です。あなたが悪い要求をしたようです。 –

+0

コードを追加しました –

+2

あなたのアカウントのsidとトークンに '{{}}'を含めていますか? – kulkarniankita

答えて

0

私はaccount_sid変数とauth_token変数を定義している間中括弧を削除するのを忘れていました。中括弧を削除した後、正常に動作しています。

修正されたコード:

from twilio.rest import TwilioRestClient 

    account_sid = " authorization sid copied correctly from the site " # Your Account SID from www.twilio.com/console 
    auth_token = " authorization token copied correctly from the site " # Your Auth Token from www.twilio.com/console 

    client = TwilioRestClient(account_sid, auth_token) 

    message = client.messages.create(body="Hey this is a Test SMS", 
     to="+919551771607", # Replace with your phone number 
     from_="+14066234282") # Replace with your Twilio number 

    print(message.sid) 
関連する問題