python - TypeError: 无法使用 Bit.ly_API 连接 'str' 和 'dict' 对象错误
问题描述
我有点问题。我对python还是很陌生。所以dict对我来说很新。我知道在我去的时候解决问题,并希望从我的错误中吸取教训。
所以错误在下面,第一个文本变量中带有“shortURL”。只是想知道这个问题意味着什么以及我该如何解决它?我在网上查看了一下,并没有完全理解为什么很多问题都在查看字符串但 bit.ly_api 只是返回一个 URL。
谢谢你的帮助 :)
print("")
print("Welcome to Sole Retriever Tweet Formulator b0.1")
type = (raw_input('What kind of tweet would you like to do?' + '\n' + '1. Store URL + Website Site' + '\n' + '2.Website URL Only' + '\n'))
if type == ('1'):
store1 = (raw_input('What is the store name hosting the Off-White x Converse Raffle? '))
storeURL = (raw_input('What is the direct URL to the raffle? '))
shortURL = b.shorten(storeURL)
text = ('Woof! ' + store1 + ' raffle is now live for the Off-White x Converse Chuck Taylor!' + '\n' + '\n' + shortURL + '\n' + '\n' + 'For raffle details and where to enter check and filter by "live" -' + '\n' + '\n' + 'https://www.soleretriever.com/off-white-x-converse-chuck-taylor/' + '\n' + '\n' + '#soleretriever #offwhite #converse #sneakers')
print (text)
os.system("echo '%s' | pbcopy" % text)
print ('\n')
print ('Copied to Clipboard')
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter.update_status(status=text)
if type == ('2'):
store = (raw_input('What is the store name hosting the Off-White x Converse Raffle? '))
text = ('Woof! ' + store + ' raffle is now live for the Off-White x Converse Chuck Taylor!' + '\n' + '\n' + 'For raffle details and where to enter check and filter by "live" -' + '\n' + '\n' + 'https://www.soleretriever.com/off-white-x-converse-chuck-taylor/' + '\n' + '\n' + '#soleretriever #offwhite #converse #sneakers')
print (text)
os.system("echo '%s' | pbcopy" % text)
print ('\n')
print ('Copied to Clipboard')
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter.update_status(status=text)
解决方案
调用b.shorten(storeURL)
将返回一个dict
键/值对,包括url
. 当您像在print()
. 我建议像:
response = b.shorten(storeURL)
shortURL = response['url']
推荐阅读
- php - PHP 查看/编辑显示的数据
- python - 使用 Folium GeoJson 绘制 Pandas 数据框数据
- r - 为克里金拟合变异函数
- dataframe - 按 DataFrame 的列分组,然后使用 pyspark 按另一列分组数据来分解结果
- r - 有条件地添加几个新列的更好方法,填充依赖于其他列条目的条目
- firebase - 在所有情况下都允许创建和读取但如果数据在 firebase 实时数据库中不存在,则不允许更新
- python-3.x - 在珊瑚 edgetpu 上运行推理会产生 IndexError: index 10 is out of bounds for axis 0 with size 10
- javascript - 为什么我的 Echo 服务器不能在 localhost 上运行?
- python - 通过检查值是否在特定列的列表中或不在 python 中来过滤 Spark 数据帧?
- c++ - Bazel 目标在 gcc 中编译,但在 emscripten 中失败