に変更すると、Python 3からいくつかのコードを変更する必要があります。* * 2.7になります。 Pythonでコードdata = urllib.parse.urlencode(values)
2.7"data = urllib.parse.urlencode(values)"をpython 2.7
python3.*
import urllib.parse
import urllib.request
def sendsms(phonenumber,textcontent):
url = 'http://urls?'
values = {'username' : 'hello',
'password' : 'world',
'dstaddr' : phonenumber ,
'smbody': textcontent
}
data = urllib.parse.urlencode(values)
data = data.encode('Big5')
req = urllib.request.Request(url, data)
with urllib.request.urlopen(req) as response:
the_page = response.read()
python 2.7
from urlparse import urlparse
from urllib2 import urlopen
from urllib import urlencode
def sendsms(phonenumber,textcontent):
url = 'http://urls?'
values = {'username' : 'hello',
'password' : 'world',
'dstaddr' : phonenumber ,
'smbody': textcontent
}
data = urllib.parse.urlencode(values) #python 3.* code, what about python 2.7 ?
data = data.encode('Big5')
req = urllib.request.Request(url, data)
with urllib.request.urlopen(req) as response:
the_page = response.read()
おかげで作業することができ、最初に,,あなたのコードはほとんどが正しい、と私は考える」(REQ )を "response = urllib2.urlopen(req)"に変更する必要があります。そうでなければ、 "AttributeError:addinfourlインスタンスに属性 '__exit__'がありません"というエラーが発生します。 –