简体   繁体   English

将数据库值分配给 Python 变量

[英]Assigning a database value to a Python Variable

Making a simple script which grabs the latest value from the database and sends over HTTP GET to a destination制作一个简单的脚本,从数据库中获取最新值并将 HTTP GET 发送到目的地

however when I use "mycursor.fetchone()" I get returned the value ""(Decimal('21.00'),)"然而,当我使用“mycursor.fetchone()”时,我得到返回值“”(Decimal('21.00'),)”

Am I missing something?我错过了什么吗? I'd like to just extract a raw value我只想提取一个原始值

Code snippet:代码片段:

mycursor.execute("SELECT RAINFALL FROM WATHER_MEASUREMENT")
rainfall = mycursor.fetchone()

#create a URL variable 
 URL='https://*****'
 PARAMS = "temp={temperature}&pressure={pressure}&rh={humidity}&precip={rainfall}".format(**vars())

requests.get(url = URL, params = PARAMS)

fetchone returns dict not value fetchone 返回字典而不是值

add this after second line:在第二行之后添加:

rainfall = rainfall['RAINFALL']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM