I'm trying to run this Telegram image downloader:
https://github.com/fabifrank/telegram-image-downloader
When I run it I get an error:
AttributeError: 'MessageMediaPhoto' object has no attribute 'document'
The code looks like this:
if(debug_enabled):
print(update)
if update.message.media is not None:
file_name = 'unknown name';
attributes = update.message.media.document.attributes
for attr in attributes:
if isinstance(attr, types.DocumentAttributeFilename):
file_name = attr.file_name
print("[%s] Download queued at %s" % (file_name, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))
message = await update.reply('In queue')
await queue.put([update, message])
I'm using Python 3.10
That's because MessageMediaPhoto does not have document but MessageMediaDocument has. I had the same issue and I used continue to skip through the exception.
async for message in takeout.iter_messages(channel, wait_time=0):
try:
print(message.media.document)
except:
continue
This will print out the document name if there is any otherwise it will show nothing. Hope it helps!
Related
This question already has answers here:
Why do I get AttributeError: 'NoneType' object has no attribute 'something'?
(11 answers)
Closed last year.
Hey i need a hand this is my first post on here so i don't know how to do this but i would like to find out how to fix my issue i am new to coding
def get_audio():
with sr.Microphone() as source:
audio = listener.listen(source)
said =''
try:
said = r.recognize_google(audio)
print(said)
except Exception as e:
print('Exception' + str(e))
Wake = 'hey friday'
while True:
text = get_audio()
if text.count(Wake) < 0:
talk('I am ready sir')
Your get_audio function must return something.
text gets nothing from get_audio so it emits AttributeError.
For those of you who have experience with Strava API - I used the documentation on their developer site: https://developers.strava.com/docs/reference/#api-Activities-getLoggedInAthleteActivities
However, copying their code over I get an attribute error-
AttributeError: 'ActivitiesApi' object has no attribute 'getActivityById'
AttributeError: 'ActivitiesApi' object has no attribute 'getLoggedInAthleteActivities'
Any idea why? Obviously inputted my ID/secret/token as from their website. Code below:
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
STRAVA_CLIENT_ID = MY_CLIENT_ID
STRAVA_CLIENT_SECRET = 'MY_CLIENT_SECRET'
STRAVA_ACCESS_TOKEN = 'MY_ACCESS_TOKEN'
swagger_client.configuration.access_token = STRAVA_ACCESS_TOKEN
api_instance = swagger_client.ActivitiesApi()
def get_activity_data():
activity_id = 3307145226
includeAllEfforts = True # Boolean | To include all segments efforts. (optional)
try:
# Get Activity
api_response = api_instance.getActivityById(id,
includeAllEfforts=includeAllEfforts)
pprint(api_response)
except ApiException as e:
print("Exception when calling ActivitiesApi->getActivityById: %s\n" % e)
return
Looks like you have an error for passing the id to getActivityById. Your activity id variable is activity_id but you're passing in id. Not sure if that will fix your issue or not but it's a start.
Code:
import time
import giphy_client
from giphy_client.rest import ApiException
from pprint import pprint
def giphyapi():
api_instance = giphy_client.DefaultApi()
api_key = '################################'
tag = 'test'
rating = 'pg-13'
fmt = 'json'
try:
# Search Endpoint
api_response = api_instance.gifs_random_get(api_key, tag = tag, rating = rating, fmt = fmt)
## here’s where I want to do stuff with the data
except ApiException as exc:
print("Exception when calling DefaultApi->gifs_random_get: %s\n" % exc)
return None
giphyapi()
Hi! How do I convert api_instance into something manipulatable, such as a dict?
This is the same problem as this, but the solution that the question author found sadly did not work for me.
I have tried print(api_response.data[0].images.type), but that threw this error:
TypeError: 'RandomGif' object is not subscriptable
I also tried this:
for block in api_response["data"]:
giftype = block["type"]
But that threw this error:
TypeError: 'InlineResponse2002' object is not subscriptable
I’m using Python 3.8.1, and I’m also using giphy-python-client. Here is a list of RandomGif models. The one I’m trying to fetch in the two examples of what I tried above is type.
Any help is greatly appreciated! 🙂
I solved it thanks to shoot2thr1ll284 on Reddit.
You just use api_response.data.type and replace type with the property that you want to fetch.
I'm trying to create a bot that will retweet and promote some of my other accounts. But i receive the below error
AttributeError: 'Twython' object has no attribute 'getUserTimeline'
my code is:
search_results = twitter.getUserTimeline(sreen_name="SCREENNAME", count = 2,)
try:
for tweet in search_results["statuses"]:
twitter.retweet(id = tweet["id_str"])
except TwythonError as e:
print e
Can anyone help?
According to the twithon documentation there is no getUserTimeline function there is however a get_user_timeline function.
You should change the following call:
twitter.getUserTimeline
to be:
twitter.get_user_timeline
I'm trying to use spynner to auto-click some button in the HTML source code as a small test. But I'm receiving this error.
Traceback (most recent call last):
File "build\bdist.win32\egg\spynner\browser.py", line 287, in _on_reply
AttributeError: 'Browser' object has no attribute 'manager'
Below is my code, which is following the guide here:https://github.com/makinacorpus/spynner/blob/master/examples/webkit_methods.py
import spynner
import libxml2
proxy_ip = "xxx.xxx.xxx.xxx";
browser = spynner.Browser()
# setting proxy ip
browser.set_proxy(proxy_ip :'8080');
browser.show()
try:
browser.load(url='http://xxx.html', load_timeout=10, tries=1)
except spynner.SpynnerTimeout:
print 'Timeout.'
else:
browser.wk_click('a[id="voteProjectBtn_10353150"]', wait_load=True)
browser.close()
I'm using Python 2.7, thanks for the help!
before browser.close(), you must distroy the loop javascript, some website has timming script, so you need distroy these script
see the browser.py, change the method "_manager_create_request" ,
before browser.close(), set self.closeflag = True
def _manager_create_request(self, operation, request, data):
if self.closeflag:
return None
url = unicode(request.url().toString())
operation_name = self._operation_names[operation].upper()
self._debug(INFO, "Request: %s %s" % (operation_name, url))
for h in request.rawHeaderList():
self._debug(DEBUG, " %s: %s" % (h, request.rawHeader(h)))
if self._url_filter:
if self._url_filter(self._operation_names[operation], url) is False:
self._debug(INFO, "URL filtered: %s" % url)
request.setUrl(QUrl("about:blank"))
else:
self._debug(DEBUG, "URL not filtered: %s" % url)
reply = QNetworkAccessManager.createRequest(self.manager,
operation, request, data)
return reply