Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9184075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:57:26+00:00 2026-06-17T18:57:26+00:00

I have been looking at a tutorial on how to send sms texts through

  • 0

I have been looking at a tutorial on how to send sms texts through the rasp pi. Here is the code that I have and I’m not sure why I have an error.

#!/usr/bin/python 
#----------------------------------- 
# Send SMS Text Message 
# 
# Author : Matt Hawkins 
# Site : http://www.raspberrypi-spy.co.uk/ 
# Date : 30/08/2012 
# 
# Requires account with TxtLocal 
# http://www.txtlocal.co.uk/?tlrx=114032 
#  
#----------------------------------- 

# Import required libraries 
import urllib # URL functions 
import urllib2 # URL functions 

# Define your message 
message = 'Test message sent from my Raspberry Pi' 

# Set your username and sender name. 
# Sender name must alphanumeric and 
# between 3 and 11 characters in length. 
username = 'jonfdom1@aol.com' 
sender = 'Jonny.D' 

# Your unique hash is available from the docs page 
# https://control.txtlocal.co.uk/docs/ 
hash = '8fe5dae7bafdbbfb00c7aebcfb24e005b5cb7be8' 

# Set the phone number you wish to send 
# message to. 
# The first 2 digits are the country code. 
# 44 is the country code for the UK 
# Multiple numbers can be specified if required 
# e.g. numbers = ('447xxx123456','447xxx654321') 
numbers = ('447xxxxxx260') 

# Set flag to 1 to simulate sending 
# This saves your credits while you are 
# testing your code. 
# To send real message set this flag to 0 
test_flag = 1 

#----------------------------------- 
# No need to edit anything below this line 
#----------------------------------- 

values = {'test' : test_flag, 
'uname' : username, 
'hash' : hash, 
'message' : message, 
'from' : sender, 
'selectednums' : numbers } 

url = 'http://www.txtlocal.com/sendsmspost.php' 

postdata = urllib.urlencode(values) 
req = urllib2.Request(url, postdata) 

print 'Attempt to send SMS ...' 

try: 
response = urllib2.urlopen(req) 
response_url = response.geturl() 
if response_url==url: 
print 'SMS sent!' 
except urllib2.URLError, e: 
print 'Send failed!' 
print e.reason

And here is the error message I have popping up on the terminal

 File "send_sms.py", line 331
    response = urllib2.urlopen(req) 
           ^
IndentationError: expected an indented block
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:57:27+00:00Added an answer on June 17, 2026 at 6:57 pm

    Python requires proper indentation, like this:

    try: 
        response = urllib2.urlopen(req) 
        response_url = response.geturl() 
        if response_url==url: 
            print 'SMS sent!' 
    except urllib2.URLError, e: 
        print 'Send failed!' 
        print e.reason
    

    Here’s a section on Python indentation from Dive Into Python 3.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking everywhere but could not find a tutorial for this. I
I've been looking at the code in this tutorial , and I found that
I have been looking for a tutorial that shows or explains how to display
I have been looking for a while for an API/Tutorial/Program that is an entirely
I've been looking through the tutorial : http://www.vogella.de/articles/AndroidSQLite/article.html and SQLite seems to have all
I have been looking over the internet, but could not find the perfect tutorial
I have been looking through the Java Tutorials at the Interfaces tutorial, specifically on
i have been looking for a tutorial for a scientific calculator one the web
I have been looking around for a visualization framework that would aid graph visualization
I have been looking for a tutorial to help me integrate PHPUnit with CakePHP.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.