我正在尝试删除字符b,'()
。
我遇到的问题是它说TypeError'st'不支持缓冲接口。
以下是代码的相关部分:
import urllib3
def command_uptime():
http = urllib3.PoolManager()
r = http.request('GET', 'https://nightdev.com/hosted/uptime.php?channel=TrippedNW')
rawData = r.data
liveTime = bytes(rawData.strip("b,\'()", rawData))
message = "Tripped has been live for: ", liveTime
send_message(CHAN, message)
答案 0 :(得分:3)
你拥有的是二进制数据。它不是一个字符串。你需要先解码它。
此外,您无需在条带方法中将rawData
传递给自身。
import urllib3
def command_uptime():
http = urllib3.PoolManager()
r = http.request('GET', 'https://nightdev.com/hosted/uptime.php?channel=TrippedNW')
strData = r.data.decode('utf-8')
liveTime = strData.strip("b,\'()")
message = "Tripped has been live for: %s" % liveTime
print(message)
command_uptime()
还要注意,您的message
变量是元组而不是字符串。我不知道send_message
是否期望这样。我把它格式化为一个字符串。
答案 1 :(得分:0)
删除第二个参数。
import urllib3
def command_uptime():
http = urllib3.PoolManager()
r = http.request('GET', 'https://nightdev.com/hosted/uptime.php?channel=TrippedNW')
rawData = r.data
liveTime = bytes(rawData.strip("b,'()"))
print("Tripped has been live for: %s" % liveTime)
command_uptime()
输出:
Tripped has been live for: 1 hour, 18 minutes