clairenied15 / heart_rate_sentinel_server

0 stars 0 forks source link

Sendgrid issues #10

Open clairenied15 opened 5 years ago

clairenied15 commented 5 years ago

I can't seem to get SendGrid to work. I copied the "With Mail Helper Class" code into my tachycardia function to run when the patient is tachycardic. I made my API key and put it in the code. The error that I'm getting says "HTTP Error 401: Unauthorized"

suyashkumar commented 5 years ago

This means your API key is not making it into your program correctly. Did you set the SENDGRID_API_KEY environment variable in the same terminal that you are running your server program in?

clairenied15 commented 5 years ago

I'm not sure what you mean by setting the environment variable.

clairenied15 commented 5 years ago

I copied my API key from sendgrid and replaced the SENDGRID_API_KEY variable in the sample code

suyashkumar commented 5 years ago

Check out my latest email--if you leave things as they were in the SendGrid example code but set the environment variable as mentioned in the email you should be good to go!

clairenied15 commented 5 years ago

I followed your instructions for setting the environment variable but am still getting the 401 error. This is my code:

`

                sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
                from_email = Email("claire.niederriter@duke.edu")
                to_email = Email("claireniederriter@ymail.com")
                subject = "Tachycardia"
                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)`