ich diese Python 3 Skript musste Python und jetzt muss ich es auf Python 2, aus laufen, was ich urilib sollte urlib2 ändern gelesen haben. Es sieht jedoch so aus, als ob sich die Codierungsklasse geändert hat. weil ich diesen Fehler:benötigen Python 3 Skript drehen 2.7 Skript
16:29:27 + python p.py
16:29:27 Traceback (most recent call last):
16:29:27 File "p.py", line 20, in <module>
16:29:27 binary_data = params.encode(encoding=repr,errors=strict)
16:29:27 NameError: name 'strict' is not defined
Das ist mein Python 3 Skript:
import urllib
import urllib.request
import sys
import os
url = 'http://google.com'
params = urllib.parse.urlencode({
'profile': 'dev' ,
'KEY':'bdi.key' ,
})
binary_data = params.encode(encoding='ascii',errors='strict')
response = urllib.request.urlopen(url, binary_data).read()
Das ist mein Python 2 Skript:
import urllib
import urllib2
from contextlib import closing
import sys
import os
url = 'http://google.com'
params = urllib.urlencode({
'profile': 'dev' ,
'KEY':'bdi.key' ,
})
binary_data = params.encode(encoding=repr,errors=strict)
response = urllib2.urlopen(url, binary_data).read()
Wie Kann ich es zur Arbeit bringen? Ich habe Python nie benutzt, bevor und dies ist ein Wartungs Skript, das ich in String-Codierung Funktion am Leben :)
'binary_data = params.encode (encoding = 'ascii', Fehler = 'strengen')'? Beachten Sie, dass ich Zitate '' 'um das Wort' strict' und 'repr' verwendet habe, um Python zu sagen, dass es sich um Strings und nicht um Namen handelt. –
'strict' sollte eine' string' sein encoding sollte auch eine string sein ('" ascii "') –