10000 add faq page, explain how to fix importerror problems · jseims/twilio-python@fd89fec · GitHub
[go: up one dir, main page]

Skip to content

Commit fd89fec

Browse files
author
Kevin Burke
committed
add faq page, explain how to fix importerror problems
1 parent 0f5efc0 commit fd89fec

File tree

5 files changed

+138
-5
lines changed

5 files changed

+138
-5
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2009 Twilio, Inc.
1+
Copyright (c) 2012 Twilio, Inc.
22

33
Permission is hereby granted, free of charge, to any person
44
obtaining a copy of this software and associated documentation

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ line:
1616

1717
$ curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
1818

19-
Alternately, you can [download the source code
19+
Or, you can [download the source code
2020
(ZIP)](https://github.com/twilio/twilio-python/zipball/master "twilio-python
2121
source code") for `twilio-python`, and then run:
2222

docs/faq.rst

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
==========================
2+
Frequently Asked Questions
3+
==========================
4+
5+
Hopefully you can find an answer here to one of your questions. If not, please
6+
contact `help@twilio.com <mailto:help@twilio.com>`_.
7+
8+
ImportError messages
9+
--------------------
10+
11+
If you get an error that looks like this:
12+
13+
.. code-block:: python
14+
15+
Traceback (most recent call last):
16+
File "twilio.py", line 1, in <module>
17+
from twilio.rest import TwilioRestClient
18+
File "/Users/kevin/code/twilio-python/docs/twilio.py", line 1, in <module>
19+
from twilio.rest import TwilioRestClient
20+
ImportError: No module named rest
21+
22+
Check to make sure that you don't have a file named ``twilio.py``; Python will try to
23+
load the Twilio library from your ``twilio.py`` file instead of from the Twilio
24+
library.
25+
26+
If you get an error that looks like this:
27+
28+
.. code-block:: python
29+
30+
Traceback (most recent call last):
31+
File "test.py", line 1, in <module>
32+
import twilio.rest
33+
ImportError: No module named twilio.rest
34+
35+
Your Python installation cannot find the library.
36+
37+
Check which versions of ``pip`` and Python you are running with this command in
38+
the Terminal:
39+
40+
.. code-block:: bash
41+
42+
which -a python
43+
which -a pip
44+
45+
``pip`` needs to install the Twilio library to a path that your Python executable
46+
can read from. Sometimes there will be more than one version of pip, like
47+
pip-2.5, pip-2.7 etc. You can find all of them by running ``compgen -c | grep
48+
pip``. There can also be more than one version of Python, especially if you have
49+
Macports or homebrew.
50+
51+
You also may be using an outdated version of the twilio-python library, which
52+
did not use a ``twilio.rest.TwilioRestClient`` object. Check which version of the
53+
twilio library you have installed by running this command:
54+
55+
.. code-block:: bash
56+
57+
$ pip freeze | grep twilio # Or pip-2.7 freeze etc.
58+
59+
The latest version (as of January 2012) is 3.3. If you are running an outdated
60+
version, you can upgrade with this command:
61+
62+
.. code-block:: bash
63+
64+
$ pip install --upgrade twilio
65+
66+
Note that if you have code that uses the older version of the library, it may
67+
breake when you upgrade your site.
68+
69+
Formatting phone numbers
70+
------------------------
71+
72+
Twilio always returns phone numbers that are formatted in the `E.164 format
73+
<http://en.wikipedia.org/wiki/E.164>`_, like this: ``+12125551234``. However
74+
your users may enter them like this: ``(212) 555-1234``. This can lead to
75+
problems when, for example, Twilio makes a POST request to your server with the
76+
``From`` phone number as ``+12125551234``, but you stored the phone number in
77+
your database as ``(212) 555-1234``, causing a database lookup to fail.
78+
79+
We suggest that you convert the number to E.164 format
80+
before you store it in the database. The `phonenumbers
81+
<https://github.com/daviddrysdale/python-phonenumbers>`_ library is excellent
82+
for this purpose. Install it like this:
83+
84+
.. code-block:: bash
85+
86+
$ pip install phonenumbers
87+
88+
Then you can convert user input to phone numbers like this:
89+
90+
.. code-block:: python
91+
92+
import phonenumbers
93+
94+
def convert_to_e164(raw_phone):
95+
if not raw_phone:
96+
return
97+
98+
if raw_phone[0] == '+':
99+
# Phone number may already be in E.164 format.
100+
parse_type = None
101+
else:
102+
# Assume it's a US number
103+
parse_type = "US"
104+
105+
phone_representation = phonenumbers.parse(raw_phone, parse_type)
106+
return phonenumbers.format_number(phone_representation,
107+
phonenumbers.PhoneNumberFormat.E164)
108+
109+
print convert_to_e164('212 555 1234') # prints +12125551234
110+
111+

docs/index.rst

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
====================
2-
Twilio Python
2+
Twilio Python Helper Library
33
====================
44

55
Make requests to Twilio's `REST API <http://www.twilio.com/docs/api/twiml/>`_ and create `TwiML <http://www.twilio.com/docs/api/twiml/>`_ without a hassle. And you thought Twilio couldn't get any easier.
@@ -9,11 +9,21 @@ Make requests to Twilio's `REST API <http://www.twilio.com/docs/api/twiml/>`_ an
99
Installation
1010
================
1111

12+
Install from PyPi using `pip <http://www.pip-installer.org/en/latest/>`_, a
13+
package manager for Python.
14+
1215
.. code-block:: bash
1316
1417
$ pip install twilio
1518
16-
You can also `download the source <https://github.com/twilio/twilio-python/zipball/master>`_ and install by downloading :data:`setuptools`, navigating in the Terminal to the folder containing the **twilio-python** library, and then running:
19+
Don't have pip installed? Try installing it, by running this from the command
20+
line:
21+
22+
.. code-block:: bash
23+
24+
$ curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
25+
26+
Or, install the library by `downloading the source <https://github.com/twilio/twilio-python/zipball/master>`_, installing :data:`setuptools`, navigating in the Terminal to the folder containing the **twilio-python** library, and then running:
1727

1828
.. code-block:: bash
1929
@@ -89,6 +99,17 @@ so only use when you really need to dive deep into the library.
8999

90100
api
91101

102+
Frequently Asked Questions
103+
==========================
104+
105+
What to do if you get an ``ImportError``, and some advice about how to format
106+
phone numbers.
107+
108+
.. toctree::
109+
:maxdepth: 2
110+
111+
faq
112+
92113
Support and Development
93114
==========================
94115
All development occurs over on `Github <https://github.com/twilio/twilio-python>`_. To checkout the source,
@@ -103,3 +124,4 @@ Report bugs using the Github `issue tracker <https://github.com/twilio/twilio-py
103124
If you have questions that aren't answered by this documentation, ask the `#twilio IRC channel <irc://irc.freenode.net/#twilio>`_
104125

105126
See the :doc:`/changelog` for version history.
127+

twilio/rest/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def __init__(self, account=None, token=None, base="https://api.twilio.com",
133133
def participants(self, conference_sid):
134134
"""
135135
Return a :class:`Participants` instance for the :class:`Conference`
136-
with conference_sid,
136+
with the given conference_sid
137137
"""
138138
base_uri = "%s/Conferences/%s" % (self.account_uri, conference_sid)
139139
return Participants(base_uri, self.auth)

0 commit comments

Comments
 (0)
0