Raspberry pi 'Response IndentationError'

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

Answers


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.


  • statement grouping is done by indentation [...]

source


Need Your Help

Display Image from Embedded Resource in HTML in .NET App

c# html vb.net

I create a HTML report inside a .net application, into which I want to display an image, which is going to come from a DLL where it is stored as an embedded resource.

How to force CKEditor to use HTML Numbers instead of special Characters

ckeditor special-characters html-entities html-encode

How can I force CKEditor to automatically convert special Characters to HTML Numbers?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.