我收到错误消息但不知道如何继续,错误消息显示如下。我已经下载了所有必要的工具供它运行但是它似乎有关键的问题。我已经输入了他们,但为了保持我的帐户私密性,我已经用隐藏的帐户用户名和密码替换了。提前致谢
C:\Users\User\Downloads\real-time-intrinio-python-master\real-time-intrinio-python-master> python realtime.py AAPL
Using Ticker: AAPL
Traceback (most recent call last):
File "realtime.py", line 18, in <module>
r=requests.get(auth_url, headers={"Authorization": "Basic %s" % base64.b64encode(os.environ['myUsername'] + ":" + os.environ['myPassword'])})
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'myUsername'
这是我正在使用的代码,第18行是“r = requests.get(auth_url,headers ...”
import websocket
import _thread
import time
import requests
import base64
import json
import sys
import os
from requests.auth import HTTPBasicAuth
try:
print ("Using Ticker: " + str(sys.argv[1]))
except:
print ("Please include ticker as first argument")
sys.exit()
auth_url = "https://realtime.intrinio.com/auth";
r=requests.get(auth_url, headers={"Authorization": "Basic %s" % base64.b64encode(os.environ['7641353c8540cd7c795c96f097185c26'] + ":" + os.environ['c15d32295cf254ab57d5523c5bf95f80'])})
socket_target = "wss://realtime.intrinio.com/socket/websocket?token=%s" % (r.text)
def on_message(ws, message):
try:
result = json.loads(message)
print (result["payload"])
except:
print (message)
def on_error(ws, error):
print ("###ERROR### " + error)
def on_close(ws):
print ("###CONNECTION CLOSED###")
def on_open(ws):
def run(*args):
security = "iex:securities:" + str(sys.argv[1]).upper()
message = json.dumps({"topic": security,"event": "phx_join","payload": {},"ref": "1"})
ws.send(message)
thread.start_new_thread(run, ())
websocket.enableTrace(True)
ws = websocket.WebSocketApp(socket_target, on_message = on_message, on_error = on_error, on_close = on_close)
ws.on_open = on_open
ws.run_forever()