1

Hello all: I have a basic program that copies a web page into a variable and checks the contents to see if a new press release was listed (i.e. by date since all PRs starts with a date in a consistent format. thanks to the help on this board it works.

Now I want to send a text message via twilio. I set my twilio account/number up and installed twilio according to these instructions. However, I get the error "ModuleNotFoundError: No Module named 'twilio'". I have uninstalled and re-installed several times. The only thing I can think of is that twilio is not installed where it should be. What are the file names and where should they be installed? Any advice would be appreciated.

===== RESTART: C:/Users/Family/Documents/Python Programs/check4newPRs.py 
June 5, 2017
found new press release dated June 5, 2017
Traceback (most recent call last):
  File "C:/Users/Family/Documents/Python Programs/check4newPRs.py", line 27, 
    in <module>
    import twilio
ModuleNotFoundError: No module named 'twilio'
>>> 

Here's my code:

# check4newPRs.py
import urllib.request

## Read web page contents into webPageCopy variable.
url = 'https://www.nwbio.com/press-releases/'
response = urllib.request.urlopen(url)
webPageCopy = response.read()

## Determining current date; populating month,day and variables
import datetime
import calendar
now = (datetime.datetime.now())
daynmbr = "05"  ## temporarily hard-coded the 5th of June, the last press released by comany. Need to remove prior to going live.

## Creating current date search string, used to search webpage. All press releases start with a date in the following format:  "June 5, 2017".
todaysdate = calendar.month_name[now.month] + " " + daynmbr.lstrip("0") + ", " + str(now.year)  ## Remove prior to going live.
##todaysdate = calendar.month_name[now.month] + " " + str(now.day).lstrip("0") + ", " + str(now.year)  ##use this one for production
print (str(todaysdate))

## ==========================================================================
## ======== press release is found, send Twilio sms text alert ========
## ==========================================================================

if (todaysdate.encode('utf-8'))  in webPageCopy:   ## todaysdate must be same byte type as the webPageCopy variable.
   print ('found new press release dated', todaysdate)

   import twilio
   import twilio.rest
   try:
       client = twilio.rest.TwilioRestClient(account_sid, auth_token)
       message = client.messages.create(
           body="New Northwest Biotherapeutics Press Release Found!!!",
           to="+1##########",
           from_="+1##########"
       )
   except twilio.TwilioRestException as e:
       print (e)
8
  • If you type pip show twilio does it return information and tell you what version you have installed? Commented Jun 12, 2017 at 14:36
  • Yes, it shows the name, version (6.3.0), summary, home-page, author, license (UNKNOWN), location (python36--32\lib\site-packages directory) Commented Jun 12, 2017 at 15:50
  • What happens if you open a python repl and try from twilio.rest import Client? Commented Jun 12, 2017 at 16:23
  • I am assuming a python "repl" is the python IDLE where you execute a program script. I created a empty script with just "from twilio.rest import Client" Apparently it worked with no error. The results were no error, just >>>>". Commented Jun 12, 2017 at 18:17
  • I uninstalled all versions and re-installed the 32-bit version. Now when I run the program, i get: Traceback (most recent call last): File "C:\Users\Family\Documents\Python Programs\check4newPRs.py", line 38, in <module> client = Client(account_sid, auth_token) NameError: name 'account_sid' is not defined >>> Commented Jun 12, 2017 at 18:19

1 Answer 1

1

Twilio developer evangelist here.

First, check which version of Twilio Python you have installed. If it is version 6, then it is the latest and you'll need to update your code.

When you want to use the Twilio REST API you should:

from twilio.rest import Client

Then you can create an instance of a Client and send a message like this:

client = Client(account_sid, auth_token)
message = client.messages.create(
    body="New Northwest Biotherapeutics Press Release Found!!!",
    to="+1##########",
    from_="+1##########"
)

Let me know if that helps at all.

Sign up to request clarification or add additional context in comments.

7 Comments

I have version 6.3. I changed my code and still get an error: from twilio.rest import Client ModuleNotFoundError: No module named 'twilio'. I really think the error has to do with some basic installation error. How does Python know where the Twilio api/dll/exe (or whatever) is?
Additional background Info: I am using Python's Integrated Development Environment (IDLE) version 3.6.1 (TK version 8.6.6). I save my python programs in a mydocs folder. Don't know if this matters...
By the way, I never said thank you, Philnash, for replying.
You might find you have multiple versions of Python installed, see this SO question for some help.
OK. I think I uncovered a problem: I have two versions of Python installed: Python 3.6 (32-bit) and python 3.6 (64-bit). The 32-bit version has a twilio folder in its "lib" directory. The 64-bit version doesn't. i changed the file associations of ".py" to use the 32.bit python version. but now i can't get into the IDLE editor. Once I find that, i'll test it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.