You need to enable JavaScript to run this app. Python3.x用robloxpy开发ROBLOX账号检查工具报字符串拼接NoneType错误
优惠活动
大模型
产品
解决方案
定价
更多

Python3.x用robloxpy开发ROBLOX账号检查工具报字符串拼接NoneType错误

Roblox账号检查工具TypeError报错修复指南

报错核心原因

robloxpy.GetUserRAP(UserID) 接口调用后返回了None空值,Python不允许字符串和None类型直接做加法拼接,因此在执行print("\nRAP: " + RapFetch)时触发TypeError: can only concatenate str (not "NoneType") to str错误。

  • 常见触发None返回的场景:输入的UserID不存在、第三方库接口适配失效导致请求无有效返回、网络波动导致接口请求超时失败。
  • 你代码里所有调用robloxpy获取的返回值(Username、LimitedValue、Followers等)都存在返回None的概率,只是本次运行时RapFetch最先命中了空值返回逻辑,触发了第一处报错。

分步修复方案

  • 所有第三方接口返回值增加空值兜底逻辑,统一转换为字符串类型后再做拼接,从根源避免类型不匹配问题
  • 增加UserID输入格式校验,过滤非数字的无效输入
  • 增加全局异常捕获,避免单次接口请求失败直接导致程序崩溃
  • 对版本过旧的第三方库做升级,适配当前ROBLOX官方接口规则

修复后可直接运行的完整代码

import robloxpy
import time

# 输入格式校验
UserID = input("Enter your ROBLOX ID: ").strip()
if not UserID.isdigit():
    print("错误:ROBLOX ID为纯数字格式,请重新输入")
    input("Press ENTER to exit console")
    exit()

# 空值安全处理函数
def convert_to_safe_str(raw_value):
    return str(raw_value) if raw_value is not None else "获取失败/无公开数据"

try:
    NameFetch = convert_to_safe_str(robloxpy.GetName(UserID))
    RapFetch = convert_to_safe_str(robloxpy.GetUserRAP(UserID))
    LimitedValueFetch = convert_to_safe_str(robloxpy.GetUserLimitedValue(UserID))
    FollowerFetch = convert_to_safe_str(robloxpy.GetFollowersCount(UserID))
    FollowingFetch = convert_to_safe_str(robloxpy.GetFollowingCount(UserID))
    BannedFetch = convert_to_safe_str(robloxpy.IsBanned(UserID))
    AccountAgeFetch = convert_to_safe_str(robloxpy.AccountAgeDays(UserID))
except Exception as e:
    print(f"接口请求异常:{str(e)}")
    input("Press ENTER to exit console")
    exit()

print("\nUsername: " + NameFetch)
time.sleep(0.1)
print("\nRAP: " + RapFetch)
time.sleep(0.1)
print("\nLimited Value: " + LimitedValueFetch)
time.sleep(0.1)
print("\nFollowers: " + FollowerFetch)
time.sleep(0.1)
print("\nFollowing: " + FollowingFetch)
time.sleep(0.1)
print("\nBanned: " + BannedFetch)
time.sleep(0.1)
print("\nAccount Age (In Days): " + AccountAgeFetch)

input("\nPress ENTER to exit console")

补充说明

  • 如果运行修复后的代码所有接口都返回"获取失败/无公开数据",大概率是本地安装的robloxpy版本过旧,与当前ROBLOX官方接口路径不匹配,执行pip install --upgrade robloxpy升级到最新版本即可解决。
  • 部分无公开交易数据的账号,其RAP、限量物品价值字段本身不存在有效返回值,这类场景下的兜底提示属于正常业务逻辑,不是程序错误。

内容的提问来源于stack exchange,提问作者MaxD

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.18 09:15:09