我是初學者到python。我是Easy APIs Project(http://gcdc2013-easyapisproject.appspot.com)的開發人員,正在使用我的項目對天氣API進行Python實現。訪問http://gcdc2013-easyapisproject.appspot.com/APIs_Doc.html查看天氣API。以下是我的實現,但它返回HTTPError: HTTP Error 400: Bad request
錯誤。HTTPError:HTTP錯誤400:錯誤的請求urllib2
import urllib2
def celsius(a):
responsex = urllib2.urlopen('http://gcdc2013-easyapisproject.appspot.com/unitconversion?q='+a+' in celsius')
htmlx = responsex.read()
responsex.close()
htmlx = html[1:] #remove first {
htmlx = html[:-1] #remove last }
htmlx = html.split('}{') #split and put each resutls to array
return str(htmlx[1]);
print "Enter a city name:",
q = raw_input() #get word from user
response = urllib2.urlopen('http://gcdc2013-easyapisproject.appspot.com/weather?q='+q)
html = response.read()
response.close()
html = html[1:] #remove first {
html = html[:-1] #remove last }
html = html.split('}{') #split and put each resutls to array
print "Today weather is " + html[1]
print "Temperature is " + html[3]
print "Temperature is " + celsius(html[3])
請幫助我..
爲什麼不使用urllib2.quote? – selllikesybok
@selllikesybok,'urllib2.quote'是對'urllib.quote'的引用。試試'import urllib,urllib2;斷言urllib2.quote是urllib.quote'。 – falsetru
答案是正確的。 –