Currently getting an error TypeError: can only concatenate str (not "NoneType") to str
Currently getting an error TypeError: can only concatenate str (not "NoneType") to str
Traceback (most recent call last):
File "<ipython-input-21-0cdf2cfacf71>", line 335, in <module>
+ my_value_a
TypeError: can only concatenate str (not "NoneType") to str
谁能帮忙解决这个错误?
代码
def get_env_var(i):
try:
letter = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'][i // 50]
return os.getenv("MY_VAR_" + letter)
except IndexError:
return "demo"
for i in range(0, len(mySymbols)):
try:
my_value_a = get_env_var(i)
#my_value_a = "demo"
#my_value_a = os.getenv("MY_VAR_K")
url_is_y = (
"https://financialmodelingprep.com/api/v3/financials/income-statement/"
+ mySymbols[i]
+ "?apikey="
+ my_value_a
)
url_bs_y = (
因此,如果 os.getenv()
的键无效,则它 return 是您作为第二个参数传递的默认值。如果您不设置此默认值,它将 return 变成 None
。可能的修复:
def get_env_var(i):
try:
letter = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'][i // 50]
return os.getenv("MY_VAR_" + letter, "demo")
except IndexError:
return "demo"
如果遇到无效键,这将 return“演示”字符串。或者,如果输出可以接受,您可以这样做:
for i in range(0, len(mySymbols)):
try:
my_value_a = get_env_var(i)
#my_value_a = "demo"
#my_value_a = os.getenv("MY_VAR_K")
url_is_y = (
"https://financialmodelingprep.com/api/v3/financials/income-statement/"
+ mySymbols[i]
+ "?apikey="
+ str(my_value_a) # This will convert None to 'None'
)
url_bs_y = (
查看 this 页面以获取有关此功能如何工作的更多信息和示例。
我建议使用最新的 URL:
"https://financialmodelingprep.com/api/v3/income-statement/"
其中没有“财务”部分。
Traceback (most recent call last):
File "<ipython-input-21-0cdf2cfacf71>", line 335, in <module>
+ my_value_a
TypeError: can only concatenate str (not "NoneType") to str
谁能帮忙解决这个错误?
代码
def get_env_var(i):
try:
letter = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'][i // 50]
return os.getenv("MY_VAR_" + letter)
except IndexError:
return "demo"
for i in range(0, len(mySymbols)):
try:
my_value_a = get_env_var(i)
#my_value_a = "demo"
#my_value_a = os.getenv("MY_VAR_K")
url_is_y = (
"https://financialmodelingprep.com/api/v3/financials/income-statement/"
+ mySymbols[i]
+ "?apikey="
+ my_value_a
)
url_bs_y = (
因此,如果 os.getenv()
的键无效,则它 return 是您作为第二个参数传递的默认值。如果您不设置此默认值,它将 return 变成 None
。可能的修复:
def get_env_var(i):
try:
letter = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'][i // 50]
return os.getenv("MY_VAR_" + letter, "demo")
except IndexError:
return "demo"
如果遇到无效键,这将 return“演示”字符串。或者,如果输出可以接受,您可以这样做:
for i in range(0, len(mySymbols)):
try:
my_value_a = get_env_var(i)
#my_value_a = "demo"
#my_value_a = os.getenv("MY_VAR_K")
url_is_y = (
"https://financialmodelingprep.com/api/v3/financials/income-statement/"
+ mySymbols[i]
+ "?apikey="
+ str(my_value_a) # This will convert None to 'None'
)
url_bs_y = (
查看 this 页面以获取有关此功能如何工作的更多信息和示例。
我建议使用最新的 URL:
"https://financialmodelingprep.com/api/v3/income-statement/"
其中没有“财务”部分。