2012-06-03 3 views
1

아래의 스크립트를 사용하여 SMS를 보내고 있지만 "인터넷 연결을 확인하십시오"라는 오류 메시지가 항상 나타납니다. 거기에 어떤 waytosms 또는 국제 번호에 SMS를 보낼 수있는 다른 서비스에 대한 작업 파이썬 스크립트가 있습니다.Python : 국제 번호로 SMS를 보내는 스크립트는 무엇입니까?

#!/usr/bin/python 

import cookielib 
import urllib2 
from getpass import getpass 
import sys 
from urllib import urlencode 
from getopt import getopt 

ask_username = True 
ask_password = True 
ask_message = True 
ask_number = True 

def Usage(): 
    print '\t-h, --help: View help' 
    print '\t-u, --username: Username' 
    print '\t-p, --password: Password' 
    print '\t-n, --number: numbber to send the sms' 
    print '\t-m, --message: Message to send' 
    sys.exit(1) 


opts, args = getopt(sys.argv[1:], 'u:p:m:n:h',["username=","password=","message=","number=","help"]) 

for o,v in opts: 
    if o in ("-h", "--help"): 
     Usage() 
    elif o in ("-u", "--username"): 
     username = v 
     ask_username = False 
    elif o in ("-p", "--password"): 
     passwd = v 
     ask_password = False 
    elif o in ("-m", "--message"): 
     message = v 
     ask_message = False 
    elif o in ("-n", "--number"): 
     number = v 
     ask_number = False 

#Credentials taken here 
if ask_username: username = raw_input("Enter USERNAME: ") 
if ask_password: passwd = getpass() 
if ask_message: message = raw_input("Enter Message: ") 
if ask_number: number = raw_input("Enter Mobile number: ") 

#Logging into the SMS Site 
url = 'http://wwwg.way2sms.com//auth.cl' 
data = 'username='+username+'&password='+passwd+'&Submit=Sign+in' 

#Remember, Cookies are to be handled 
cj = cookielib.CookieJar() 
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) 

# To fool way2sms as if a Web browser is visiting the site 
opener.addheaders = [('User-Agent','Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20091020 Ubuntu/9.10 (karmic) Firefox/3.5.3 GTB7.0')] 
try: 
    usock = opener.open(url, data) 
except IOError: 
    print "Check your internet connection" 
    sys.exit(1) 

#urlencode performed.. Because it was done by the site as i checked through HTTP headers 

message = urlencode({'message':message}) 
message = message[message.find("=")+1:] 

#SMS sending 
send_sms_url = 'http://wwwg.way2sms.com//FirstServletsms?custid=' 
#Check this line with HTTP Headers, if script is not working 
send_sms_data = 'custid=undefined&HiddenAction=instantsms&Action=custfrom950000&login=&pass=&MobNo='+number+'&textArea='+message 
opener.addheaders = [('Referer','http://wwwg.way2sms.com//jsp/InstantSMS.jsp?val=0')] 

try: 
    sms_sent_page = opener.open(send_sms_url,send_sms_data) 
    inp = open("log.html","w") 
    inp.write(sms_sent_page.read()) 
    inp.close() 

except IOError: 
    print "Check your internet connection(while sending sms)" 
    sys.exit(1) 
print "SMS sent!!!" 

제발 내가 파이썬 스크립트를 얻을 수있는 SMS 서비스를 제안하십시오.

+1

무료 또는 무료? – YumYumYum

+0

유료 또한 괜찮습니다. –

+0

간단합니다. 404 오류가 있기 때문입니다. 즉, URL을 확인하십시오. – SuperSaiyan

답변

2

twilio를 시도해 볼 수 있으며 공식 python 코드도 있습니다 (아래 링크 참조). 그러나 이것은 무료 서비스가 아니므로 pricing을 볼 수 있습니다.

https://github.com/twilio/twilio-python#readme

+0

감사합니다.하지만 인도에서도 twilio 서비스를 사용할 수 있습니까? –

+1

시도해보십시오. http://www.twilio.com/international-sms – User97693321

0

Twiliohighly recommended입니다.

from twilio.rest import TwilioRestClient 

account = "getFromYourTwilioDashboard" 
token = "getFromYourTwilioDashboard" 
client = TwilioRestClient(account, token) 

message = client.sms.messages.create(to="+yourCellNumber", from_="+yourTwilioNumber", body="Message here") 

이 무료가 아니라 사용하기 쉬운 및 신뢰성 :

이 코드는 문자 메시지를 보낼 수 Twilio를 사용합니다.

0

My free solution는 DailySMS 양식을 사용하고 대부분의 국가에서 작동 :

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 
# Free worldwide SMS sending script using DailySMS API. 
# By Multiversum 

import sys 
import requests 

forge_user_agent = 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5' 
script_url = 'http://www.uthsms.net/api/index.php' 
forge_headers = { 
    'Origin' : 'http://www.uthsms.net', 
    'Connection' : 'keep-alive', 
    'User-Agent' : forge_user_agent, 
    'Content-Type' : 'application/x-www-form-urlencoded', 
    'Referer' : script_url, 
} 

def sendsms(destphone, smsbody): 
    resp = requests.post(script_url, {'phone': destphone, 'hyderabad': smsbody}, headers=forge_headers) 

if __name__ == "__main__": 
    if len(sys.argv) < 3: 
     print "Usage: dailysms [num in international format without +] [message]" 
    else: 
     sendsms(sys.argv[1], sys.argv[2]) 
     print "Message sent" 
+1

script_url이 404 http 오류를 반환합니다. –

1

DailySMS가 없어. 스크립트가 Solinked를 사용하도록 업데이트되었습니다 : http://pastebin.com/21yft50r

하지만 너무 많이 사용하지 마십시오. 종료하지 마십시오.

관련 문제