Python TypeError:无法将'str'和'dict'对象错误与Bit.ly_API连接起来

Python TypeError:无法将'str'和'dict'对象错误与Bit.ly_API连接起来,python,string,python-2.7,directory,Python,String,Python 2.7,Directory,我有点问题。我对python还是很陌生。所以dict对我来说是很新的。我知道如何边走边解决问题,希望能从错误中吸取教训 下面是第一个文本变量中的“shortURL”错误。只是想知道这个问题意味着什么,以及我如何着手解决它?我在网上看了一眼,并没有完全理解为什么在查看字符串时会出现很多问题,但是bit.ly_api只返回一个URL 感谢您的帮助: print("") print("Welcome to Sole Retriever Tweet Formulator b0.1")

我有点问题。我对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.shortenstoreURL的调用将返回一个带有键/值对的dict,包括url。当您像在打印中一样连接字符串和dict时,Python将抛出该错误。我的建议是:

response = b.shorten(storeURL)
shortURL = response['url']

您的错误的堆栈跟踪显示了什么?它是否给出了它在哪一行以及你在哪里试图用dict连接字符串的任何提示?@Sean它在第31行,但我已经删除了最上面的代码行,因为它包含我的API键。下面的代码有问题。用+shortURL+text='Woof!'store1+“现在为灰白色x匡威查克·泰勒(Chuck Taylor)举办抽奖活动!”+”\n'+'\n'+shortURL+'\n'+'\n'+'了解抽奖详情以及在何处按live输入检查和筛选-'+'\n'+'\n'+'https://www.soleretriever.com/off-white-x-converse-chuck-taylor/“+”\n“+”\n“+”太阳猎犬灰白色匡威运动鞋“你好!谢谢你的回复。所以当我尝试这一点时,我得到一个属性错误。AttributeError:'dict'对象在没有导入语句的情况下没有属性'url',我猜您正在使用哪个库。我会检查文档或使用类似打印响应键的东西:%s%dict.keys来查看。啊,我可以将它们附加到下面-/usr/bin/env python2.7导入操作系统导入系统导入站点导入线程导入时间从twython导入bitly_api从datetime导入twython从datetime导入datetime导入TimeDelta可能与响应['url'一起工作。我已经有一段时间没有使用Python了,对不起!这很有效,非常感谢!!那么为什么它必须在[]中呢?