【发布时间】:2021-05-21 19:18:20
【问题描述】:
我正在制作一个脚本,用来自 api 的响应填充文本文档。该 api 被要求将用户名从列表转换为通用唯一标识符。我不断收到此错误,无法找到解决方法。 “json.decoder.JSONDecodeError:预期值:第 1 行第 1 列(字符 0)”
accounts.txt 示例
knapplace
Coppinator
tynow
Pman59
ButterMusty
FlyHighGuy13
Seyashi
fluzzygirl1
SquidMan55
leonrules9
BarthGimble
MTR_30
Darkshadow402
Deathmyster
Team_Everlook
Sheathok
KCFrost
mendog
Allfaal117
theLP25D
Zimyx
Blurrnis
redboy678
moose_breeder
kaser12345
import requests
import json
file1 = open('accounts.txt', 'r')
usernames = []
for line in file1:
stripped_line = line.strip()
usernames.append(stripped_line)
file1.close()
for x in usernames:
username = str(x)
url = ("https://api.mojang.com/users/profiles/minecraft/"+username+"?at=1462770000")
y = requests.get(url)
y_data = y.json()
uuid = y_data['id']
uuids = []
uuids.append(uuid)
file2 = open('uuids.txt', 'w')
file2.writelines(uuids)
file2.close()
file2 = open('uuids.txt', 'r')
lines = file2.readlines()
【问题讨论】:
-
您能否提供一个示例用户名列表,以便我们尝试调试您的代码?由于我们没有
accounts.txt文件,因此仅通过查看您的代码很难看出发生了什么。 -
我已经为你添加了一个示例
标签: python json python-3.x list python-requests