Reputation: 9
Hi I am trying to compile the below code by getting IndentationError: expected an indented block Can some one help
# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
import urllib,urllib.request,urllib.parse
class SendSms:
def init__(self,mobilenumber,message):
url = "https://www.sms4g.com/smscwebservice_bulk.aspx"
values = {'user' : 'xxx',
'passwd' : 'xxx',
'message' : message,
'mobilenumber':number,
'mtype':'N',
'DR':'Y'
}
data = urllib.parse.urlencode(values)
data = data.encode('utf-8')
request = urllib.request.Request(url,data)
response = urllib.request.urlopen(request)
print (response.read().decode('utf-8'))
Upvotes: -1
Views: 47
Reputation: 274
Python is strict about indentation. It should look more like this:
import urllib,urllib.request,urllib.parse
class SendSms:
def init__(self,mobilenumber,message):
url = "https://www.sms4g.com/smscwebservice_bulk.aspx"
values = {'user' : 'xxx',
'passwd' : 'xxx',
'message' : message,
'mobilenumber':number,
'mtype':'N',
'DR':'Y'
}
data = urllib.parse.urlencode(values)
data = data.encode('utf-8')
request = urllib.request.Request(url,data)
response = urllib.request.urlopen(request)
print (response.read().decode('utf-8'))
Check out the PEP8 guidelines for more info.
Upvotes: 1
Reputation: 186
In python your code should use indentation to mark blocks. For eg:
if(some_condition):
a=b+c;
Note the indentation after the if statement
Upvotes: 0