简体   繁体   English

AttributeError: 'dict' 对象在使用 Tweepy 时没有属性 'read'

[英]AttributeError: 'dict' object has no attribute 'read' while using Tweepy

I am completely new to python.我对python完全陌生。 I am not able to run the following code as it throws an attribute error.我无法运行以下代码,因为它会引发属性错误。 Could someone please help?有人可以帮忙吗?

import tweepy
import urllib

import json


api_key = "VdG3NjsNKg49NbNb7GMHiX"
api_secret = "yBGKwe2K3QYk5lDny1eIKiyEQawVLQKX1HbRCTRfA9hK9"
access_token_key = "110456973-H8CAAET5CBoEa6FS4CKmk98XOADnJOsxK45"
access_token_secret = "wPUlfaxs1TFrTlXs2VqJIE5ffAfclhJCWmMlLPncb"


auth = tweepy.auth.OAuthHandler(api_key,api_secret)
auth.set_access_token(access_token_key,access_token_secret)
api=tweepy.API(auth,parser=tweepy.parsers.JSONParser())

results=api.search(q="microsoft",count=100)

print type(results)
print json.load(results)
results=api.search(q="microsoft",count=100)

print type(results)
print json.load(results)

results here is already a dict . results在这里已经是一个dict

There is no need to deserialize it as JSON.无需将其反序列化为 JSON。

See: tweepy.api.API.search() which reads:请参阅: tweepy.api.API.search()其内容如下:

API.search(q[, lang][, locale][, rpp][, page][, since_id][, geocode][, show_user])

Returns tweets that match a specified query.

Parameters: 
    q – the search query string
    lang – Restricts tweets to the given language, given by an ISO 639-1 code.
    locale – Specify the language of the query you are sending. This is intended for language-specific clients and the default should work in the majority of cases.
    rpp – The number of tweets to return per page, up to a max of 100.
    page – The page number (starting at 1) to return, up to a max of roughly 1500 results (based on rpp * page.
    geocode – Returns tweets by users located within a given radius of the given latitude/longitude. The location is preferentially taking from the Geotagging API, but will fall back to their Twitter profile. The parameter value is specified by “latitide,longitude,radius”, where radius units must be specified as either “mi” (miles) or “km” (kilometers). Note that you cannot use the near operator via the API to geocode arbitrary locations; however you can use this geocode parameter to search near geocodes directly.
    show_user – When true, prepends “<user>:” to the beginning of the tweet. This is useful for readers that do not display Atom’s author field. The     default is false.

Return type:    
    list of SearchResult objects

NB: The "Return type:"注意: “返回类型:”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取 AttributeError: &#39;dict&#39; object has no attribute &#39;parse&#39; 。 在尝试读入多个 xlsx 文件时 - Getting an AttributeError: 'dict' object has no attribute 'parse' . While trying to read into multiple xlsx files AttributeError: 'dict' object 没有属性 - AttributeError: 'dict' object has no attribute Tweepy:AttributeError:状态对象没有属性_json - Tweepy : AttributeError : Status object has no attribute _json Tweepy AttributeError: 'API' object 没有属性 'search' - Tweepy AttributeError: 'API' object has no attribute 'search' 当我尝试上传图片时,Tweepy 抛出错误。 (AttributeError: 'dict' object 没有属性 'media_id_string') - Tweepy is throwing an error when I try to upload an image. (AttributeError: 'dict' object has no attribute 'media_id_string') &#39;AttributeError:&#39;NoneType&#39;对象没有属性&#39;to_dict&#39; - 'AttributeError: 'NoneType' object has no attribute 'to_dict' AttributeError: &#39;dict&#39; 对象没有属性 &#39;encode&#39; - AttributeError: 'dict' object has no attribute 'encode' Python-AttributeError:“ dict”对象没有属性“ replace” - Python - AttributeError: 'dict' object has no attribute 'replace' AttributeError:“ str”对象没有属性“ __dict__” - AttributeError: 'str' object has no attribute '__dict__' AttributeError:“dict”对象没有属性“pencolor” - AttributeError : 'dict' object has no attribute 'pencolor'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM