我正在使用Python处理一些API脚本,它接受一个参数并返回JSON。我正在使用BrawlStats库(https://github.com/SharpBit/brawlstats)。它在PyCharm中很好用,但在终端中不起作用,我不知道为什么,我尝试了一些建议,例如在脚本目录中运行“ pip install”,但仍然无济于事。我试图使用PHP运行脚本,但是它返回与终端相同的错误:https://gyazo.com/afac3d7c7e50b4c4925ec767dc5457b2 + https://gyazo.com/5a55668e5e4cd005a64dd5c702043b98。帮助将不胜感激,我被困住了,我不知道如何解决它:/
代码:
import brawlstats
import json
import sys
client = brawlstats.Client("***")
def OMEGA(LUL):
player = client.get_profile(LUL)
xxDD = {
"tag": player.tag,
"name": player.name,
"avatar": player.avatar_url,
"trophies": player.trophies,
"victories": player.victories,
"level": player.exp_level
}
print(json.dumps(xxDD))
return json.dumps(xxDD)
print(sys.argv[1])
OMEGA(sys.argv[1])
这是我使用PHP / terminal运行它时出现的错误:
Traceback (most recent call last):
File "C:/xampp/htdocs/main.py", line 23, in <module>
OMEGA(sys.argv[1])
File "C:/xampp/htdocs/main.py", line 8, in OMEGA
player = client.get_profile(LUL)
File "C:\Users\Krzysztof\AppData\Local\Programs\Python\Python36\lib\site-packages\brawlstats\core.py", line 147, in get_profile
data, resp = self._get(self.api.profile + '/' + tag)
File "C:\Users\Krzysztof\AppData\Local\Programs\Python\Python36\lib\site-packages\brawlstats\core.py", line 124, in _get
with self.session.get(url, timeout=self.timeout, headers=self.headers) as resp:
AttributeError: __enter__
最后,当我使用PyCharm运行它时,输出为:
{"tag": "CP0GU982", "name": "flick", "avatar": "https://fourjr.github.io/bs-assets/player_icons/28000000.png", "trophies": 6, "victories": 1, "level": 1}