I would like to send an email via sendgrid from Python on top of Bluemix.

Asked 2 years ago, Updated 2 years ago, 103 views

#!/usr/bin/env python
#! coding:UTF-8
import urllib2
import base64
import zlib
import json
import sys
import ssl
import datetime
import sendgrid
import sqlalchemy
from sqlalchemy import*
import ibm_db_sa.ibm_db_sa
db2 = sqlalchemy.create_engine('ibm_db_sa://dash013754:[email protected]:50000/BLUDB')
metadata=MetaData()
users=Table('users',metadata, 
Column ('user_id', Integer, primary_key=True),
Column ('user_name', String(16), nullable=False),
Column('email_address', String(60), key='email',
Column ('password', String(20), nullable=False)
)
metadata.bind=db2
metadata.create_all()
users_table=Table('users', metadata, autoload=True, autoload_with=db2)
users_table

# using SendGrid's Python Library - https://github.com/sendgrid/sendgrid-python
sg = sendgrid.SendGridClient(api_user, api_key)
message = sendgrid.Mail()
message.add_to ("[email protected]")
message.set_from("[email protected]")
message.set_subject("Sending with SendGrid is Fun")
message.set_html(stmt)

sg.send(message)

When you attempt to deploy the ,

Traceback (most recent call last):
File "server.py", line 10, in
import sendgrid
ImportError: No module named sendgrid

It falls off with .How can I install sendgrid on Bluemix?Please let me know

python bluemix

2022-09-30 20:22

1 Answers

I think you ran the pip install sendgrid and other commands when you started using sendgrid because your environment doesn't have that package.The same can be said on Bluemix, so installation is required as you say.

For Bluemix, this seems to be done by describing dependencies in requirements.txt.

http://www.ibm.com/developerworks/jp/cloud/library/cl-worldbank-charting-app/

Add the requirement.txt file to the root directory of the project.The requirement.txt file must contain all external dependencies (such as Django and PyMongo) required to run the graph generation application.Bluemix ensures that when this application runs, the requisition.txt file will be read and the dependencies listed in this file will be installed.

The requirements.txt can be used in Heroku, etc., and you will find many documents in Japanese.

Various packages, including sendgrid, are registered with the site PyPi. pip install or easy_install will check and install the latest version from this site.

https://pypi.python.org/pypi/sendgrid

In this case, there is no sendgrid package on Bluemix, so you will have to install the sendgrid package on PyPi.Then, requirements.txt will indicate which package to choose.

Therefore, you will need to describe the version of sendgrid you want to use on Bluemix.

If you want to specify the same version that you are using, you can use the pip freeze command to print a list that is compatible with requirements.txt.Read the article below.

Python Tips: I want to install my libraries together - Life with Python


2022-09-30 20:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.