st1= str()
c1= str()
c2= str()
EndCash = float()
page = requests.get('http://www.xe.com/currencyconverter/convert/?Amount=' +
str(st1) + '&From=' + (c1) + '&To=' + (c2))
tree = html.fromstring(page.content)
rate = tree.xpath('//span[@class="uccResultAmount"]/text()')
symbol = tree.xpath('//span[@class="uccToCurrencyCode"]/text()')
EndCash = rate + symbol
I am using the requests
module and lxml
to harvest currency rates from the Internet. I am encountering problems when doing this. I am getting a must be str, not float
error. I'm using this line of code for a label in tkinter
so the output of this, which is EndCash
, should appear in the label. This code works independently but in tkinter
it does not work
>>>TypeError: must be str, not float
on first statememt.
like this your code should work, you have to trasform floats to string after defining them
page = requests.get('http://www.xe.com/currencyconverter/convert/?Amount=' + str(st1) + '&From='+str(c1) +'&To=' + str(c2))
tree = html.fromstring(page.content)
rate = tree.xpath('//span[@class="uccResultAmount"]/text()')
symbol = tree.xpath('//span[@class="uccToCurrencyCode"]/text()')
EndCash = str(rate + symbol)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.