Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:只能将str(而不是“int”连接到str,Firebase数据库问题_Python_Firebase_Typeerror - Fatal编程技术网

Python TypeError:只能将str(而不是“int”连接到str,Firebase数据库问题

Python TypeError:只能将str(而不是“int”连接到str,Firebase数据库问题,python,firebase,typeerror,Python,Firebase,Typeerror,我是新的编码,我正在创建一个应用程序,使用firebase注册用户的数据。我正在尝试更新用户创建后的好友id号,但出现此错误,有人能帮我修复此问题吗 Python代码 friend_patch_data = '{"next_friend_id": %s}' % str(my_friend_id+1) friend_patch_req = requests.patch("https://the-notebook-196cb.firebaseio.com/.json?auth=" + idToke

我是新的编码,我正在创建一个应用程序,使用firebase注册用户的数据。我正在尝试更新用户创建后的好友id号,但出现此错误,有人能帮我修复此问题吗

Python代码

friend_patch_data = '{"next_friend_id": %s}' % str(my_friend_id+1)

friend_patch_req = requests.patch("https://the-notebook-196cb.firebaseio.com/.json?auth=" + idToken,
                         data=friend_patch_data)
我正在上传的数据:

my_data = '{"Avatar": "bruh.png", "Friends": "", "Notebooks": "", "my_friend_id": %s}'% my_friend_id
我犯了一个错误

TypeError:只能将str(而不是“int”)连接到str


当您分配
my\u data
时,您说的是
my\u friend\u id
是一个字符串,而它似乎不是

在格式字符串中使用
%d

my_data = '{"Avatar": "bruh.png", "Friends": "", "Notebooks": "", "my_friend_id": %d}' % my_friend_id
或使用:

如果您使用的是Python 3,则可以使用f字符串:

my_data = f'{{"Avatar": "bruh.png", "Friends": "", "Notebooks": "", "my_friend_id": {my_friend_id}}}'

当询问产生异常的代码时,始终在问题中包含完整的回溯。复制回溯并将其粘贴到问题中,然后将其格式化为代码(选择它并键入ctrl-k),如果您经常使用错误消息进行搜索-
TypeError:只能将str(而不是“int”)连接到str
,您将得到大量的结果进行筛选,并了解问题可能是什么。
my_data = f'{{"Avatar": "bruh.png", "Friends": "", "Notebooks": "", "my_friend_id": {my_friend_id}}}'