jeder, ich muss etwas Code von Python 3. * zu 2.7 ,,, ,, aber ich weiß nur nicht, was ist das Code data = urllib.parse.urlencode(values)
in Python 2,7ändern "data = urllib.parse.urlencode (Werte)" zu 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()
Dank für Ihre Antwort arbeiten ,, Ihr Code ist meistens richtig, und ich denke, "mit urllib2.urlopen (erf) als Antwort: the_page = response.read() "muss zu" response = urllib2.urlopen (req) ",,, sonst wird es Fehler" AttributeError: addinfour-Instanz hat kein Attribut '__exit__' " –