如何在Python中编辑URL而不出现HTTP500错误



我正试图在Python中创建一个函数,该函数将使用两个日期,并将它们转换为Unix时间戳,然后在带有pd.read_csv的html字符串中使用这些字符串,将日期过滤器应用于从Yahoo Finance下载的文件。

import pandas as pd
import numpy as np
from datetime import timezone as tz
from datetime import datetime as dt
def Datetounix(d):#enter dates as [y, m d]
p = dt(d[0], d[1], d[2])
return(str(p.replace(tzinfo=tz.utc).timestamp()))
d1 = [2020, 4, 14]#enter dates as [y, m, d]
d2 = [2021, 4, 14]#enter dates as [y, m, d]
aaplsite = f"https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1={Datetounix(d1)}&period2={Datetounix(d2)}&interval=1d&events=history&includeAdjustedClose=true"

通过测试,我发现转换函数是有效的,但是当我只输入fstring并应用其中的值时,当我通过pd.read_csv运行字符串时,我会得到

HTTPError: HTTP Error 500: Internal Server Error

请根据需要进行澄清。

代码不是问题所在。

该错误表明问题出在web服务器上,可能是由于出现意外情况

您可以在这里看到HTTP服务器的所有错误代码,以供将来参考

最新更新