1
(忽略g.text和p.content回報「你無權查看此內容」從plug.dj)我得到的錯誤類型錯誤:不能連接「STR」和「響應」對象
Traceback (most recent call last):
File "plugling.py", line 20, in <module>
r.send('{"a":"auth","p":"'+g+'","t":'+t+'}')
TypeError: cannot concatenate 'str' and 'Response' objects
運行此代碼:
import time
from websocket import create_connection
import requests
import calendar
slug = 'sfoc'
r = create_connection("wss://godj.plug.dj/socket")
t = calendar.timegm(time.gmtime())
token = 'https://plug.dj/_/auth/token'
join = 'https://plug.dj/_/rooms/join'
pl = {'slug': 'sfoc'}
g = requests.get(token)
print g.text
p = requests.post(join, data=pl)
print p.content
r.send('{"a":"auth","p":"'+g+'","t":'+t+'}')
result = r.recv()
print result
r.close()
它沒有用%s的變量要麼喜歡我。我不知道我做錯了什麼。如果我沒有清楚地說明,請提前致謝,並告訴我。
爲錯誤說'g'是'響應'對象,所以你不能將它與一個字符串連接起來,你可以在這裏使用'g.text' – Kasramvd