How to customize a PHP url token with a defined variable in a python script? -
i getting typeerror: cannot concatenate 'str' , 'int' objects
when want customise url token "id" needed.
in place of 1 single result returned single id (say 303) want have result ids declared in variable "station" retrieved url. code follows:
import urllib2 import json #assign url url="http://ewodr.wodr.poznan.pl/doradztwo/swd/swd_api.php?dane={%22token%22:%22pcss%22,%22operacja%22:%22stacje%22}" # open url json_obj= urllib2.urlopen(str(url)) output= json.load(json_obj) station_res= output ['data'] ['features'] item in station_res: station= item['id'] url1="http://ewodr.wodr.poznan.pl/doradztwo/swd/meteo_api.php?dane={%22token%22:%22pcss%22,%22id%22:}" +str(station) json_obj2= urllib2.urlopen(str(url1)) output2= json.load(json_obj2) for item2 in output2 ['data']: print item2
i tried put "stations" string in "url1" still doesn't recognise url , returns error:
traceback (most recent call last): `file "stations.py", line 23, in <module>` `for item2 in output2 ['data']:`
keyerror: 'data'
try with:
station= item ['id'] url1="http://ewodr.wodr.poznan.pl/doradztwo/swd/meteo_api.php?dane={%22token%22:%22pcss%22,%22id%22:}" +str(station)
you trying join string integer, generate error.
Comments
Post a Comment