我正在尝试将文本插入带有 %s 的大 url。每当我运行它时,我都会收到错误:TypeError: a float is required
这看起来很愚蠢,因为我将字符串放入字符串中并且不涉及 float 或整数。任何帮助都是极好的!我的代码在下面
import datetime
date = (datetime.datetime.today().date() - datetime.timedelta(days=100)).strftime("%m/%d/%Y")
date = str(date)
date = date.replace("/","%2F")
def genUrl(account, date, lastName, firstName):
url = "https://arpmp-ph.hidinc.com/arappl/bdarpdmq/pmqadhocrpt.html?a=&page=recipqry&disp-bdate=%s&disp-edate=%s&recip-list=02685245&output=web&dt-sort-by=rcpdt&mode=Recipient_Query&w_method=POST&suplist=BM0650386&base-prsb=0&base-phrm=0&base-recip=1&tot-recip=1&report=PHY&recip-sex=A&recip-dob=01%2F21%2F1964&account-id=%s&date=%s&dob-days=0&recip-name=%s&recip-fname=%s&enum-read-cnt=2&enum-keep-cnt=1&etime=5&pagename=pmqrecipqry&pdmdir=arpdm&pdmstate=ar&scriptname=%2Farappl%2Fbdarpdmq&exprecip=yes" %(date, str(datetime.datetime.now()), account, date, lastName, firstName)
print(url)
genUrl("example",date, "Smith", "Jogn")
对不起,如果我只是犯了一个愚蠢的错误而没有注意到它。我对 Python 比较陌生
最佳答案
这是因为您要将 "/"
替换为 "%2F"
,这是 float 的 Python 占位符。
import datetime
date = (datetime.datetime.today().date() - datetime.timedelta(days=100)).strftime("%m/%d/%Y")
date = str(date)
date = date.replace("/","%2F")
def genUrl(account, date, lastName, firstName):
url = "https://arpmp-ph.hidinc.com/arappl/bdarpdmq/pmqadhocrpt.html?a=&page=recipqry&disp-bdate={}&disp-edate={}&recip-list=02685245&output=web&dt-sort-by=rcpdt&mode=Recipient_Query&w_method=POST&suplist=BM0650386&base-prsb=0&base-phrm=0&base-recip=1&tot-recip=1&report=PHY&recip-sex=A&recip-dob=01%2F21%2F1964&account-id={}&date={}&dob-days=0&recip-name={}&recip-fname={}&enum-read-cnt=2&enum-keep-cnt=1&etime=5&pagename=pmqrecipqry&pdmdir=arpdm&pdmstate=ar&scriptname=%2Farappl%2Fbdarpdmq&exprecip=yes".format(date, str(datetime.datetime.now()), account, date, lastName, firstName)
print(url)
genUrl("example",date, "Smith", "Jogn")
关于python - 格式化字符串 (%s) 返回 TypeError : a float is required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45911113/