2017-02-11 2 views
0

Cloud9 Python 환경에서 sendgrid를 사용하는 데 문제가 있습니다. 이것은 SendGrid 설치 옵션에서 제안한 코드입니다.Send7 with Cloud9 with WebApi Python 옵션

참고 : 실제 API를 생성했으며 분명히 "YOUR_API_KEY"이 적절한 키로 대체되었습니다.

에코 "수출 SENDGRID_API_KEY = 'YOUR_API_KEY'"> sendgrid.env

에코 "sendgrid.env는">> .gitignore

sendgrid가 설치 PIP 소스 ./sendgrid.env**

# using SendGrid's Python Library 
# https://github.com/sendgrid/sendgrid-python 
import sendgrid 
import os 
from sendgrid.helpers.mail import * 

sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) 

    from_email = Email("[email protected]") 
    to_email = Email("[email protected]") 
    subject = "Sending with SendGrid is Fun" 
    content = Content("text/plain", "and easy to do anywhere, even with Python") 
    mail = Mail(from_email, subject, to_email, content) 
    response = sg.client.mail.send.post(request_body=mail.get()) 


print(response.status_code) 
print(response.body) 
print(response.headers) 

이 오류

> Traceback (most recent call last): File "schedule.py", line 92, in 
> <module> 
>  response = sg.client.mail.send.post(request_body=mail.get()) File 
> "/usr/local/lib/python2.7/dist-packages/python_http_client/client.py", 
> line 204, in http_request 
>  return Response(self._make_request(opener, request)) File "/usr/local/lib/python2.7/dist-packages/python_http_client/client.py", 
> line 138, in _make_request 
>  return opener.open(request) File "/usr/lib/python2.7/urllib2.py", line 410, in open 
>  response = meth(req, response) File "/usr/lib/python2.7/urllib2.py", line 523, in http_response 
>  'http', request, response, code, msg, hdrs) File "/usr/lib/python2.7/urllib2.py", line 448, in error 
>  return self._call_chain(*args) File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain 
>  result = func(*args) File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default 
>  raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 401: Unauthorized 
로그인을 얻기

누락 된 라이브러리와 관련이 있습니까? 일부 Cloud9 제한?

답변