AttributeError:“NoneType”对象没有属性endswith

2024-10-01 13:36:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我要运行下面的文件,但我遇到了一个错误。我不知道怎么解决这个问题。请引导我。谢谢对所有人。在

我有个错误:

Traceback(most recent call last)    :
  File "scripts/generate_simulated_pair.py", line 55, in <module>
    pair, d.strftime("%Y%m%d")
  File "home/farshad/venv/qsforex/lib/python2.7/posixpath.py", line 77, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'

错误引用的部分文件:

^{pr2}$

我的设置.py公司名称:

from decimal import Decimal
import os


ENVIRONMENTS = { 
"streaming": {
    "real": "stream-fxtrade.oanda.com",
    "practice": "stream-fxpractice.oanda.com",
    "sandbox": "stream-sandbox.oanda.com"
},
"api": {
    "real": "api-fxtrade.oanda.com",
    "practice": "api-fxpractice.oanda.com",
    "sandbox": "api-sandbox.oanda.com"
}
}

CSV_DATA_DIR = os.environ.get('desktop/trading python files/trading      system/qsforex-backtesting-data', None)
OUTPUT_RESULTS_DIR = os.environ.get('desktop/trading python files/trading  system/qsforex-backtesting-results', None)

DOMAIN = "practice"
STREAM_DOMAIN = ENVIRONMENTS["streaming"][DOMAIN]
API_DOMAIN = ENVIRONMENTS["api"][DOMAIN]
ACCESS_TOKEN = os.environ.get('OANDA_API_ACCESS_TOKEN', None)
ACCOUNT_ID = os.environ.get('OANDA_API_ACCOUNT_ID', None)

BASE_CURRENCY = "USD"
EQUITY = Decimal("1000.00")

Tags: pycomnoneapistreamgetosdomain
1条回答
网友
1楼 · 发布于 2024-10-01 13:36:22

引发异常是因为settings.CSV_DATA_DIRos.path.join()的第一个参数被设置为None。在

它被设置为None,因为环境变量desktop/trading python files/trading system/qsforex-backtesting-data不存在:

CSV_DATA_DIR = os.environ.get('desktop/trading python files/trading      system/qsforex-backtesting-data', None)

os.environ对象是一个映射,如果第一个参数(键)不存在,.get()方法返回第二个参数(None)。在

相关问题 更多 >