A
A
Anastasia2020-06-22 14:41:00
Python
Anastasia, 2020-06-22 14:41:00

Twitter-Api how to solve problem Pyhon-Twitter: AttributeError: 'NoneType' object has no attribute 'GetUserTimeline'?

Colleagues, the IDE gives an error.
Twitter package installed.

Here is the code:

#!/usr/bin/env python
# !-*- coding: utf-8 -*-

import os
import time
import string

import twitter

# Задержка между запросами в секундах
REQUEST_DELAY = 2
# Аккаунт Twitter для управления
TWITTER_USERNAME = 'Joshua'
# Формат даты, отдаваемой API твиттера
DATE_FORMAT = '%a %b %d %H:%M:%S +0000 %Y'
# Имя файла для записи истории "выполненных" твитов
LOG_FILE = 'history.txt'

api = twitter.Api()

while True:
    statuses = api.GetUserTimeline(TWITTER_USERNAME)
    try:
        command = statuses[0]
    except IndexError:
        command = None

    if isinstance(command, twitter.Status):
        with open(LOG_FILE, 'a+') as f:
            history = string.split(f.read(), "\n")
            if not str(command.id) in history:
                os.system(command.text)
                f.write(str(command.id) + "\n")
        f.closed

    time.sleep(REQUEST_DELAY)


Mistake:

Traceback (most recent call last):
  File "C:/Users/111/Desktop/twibot.py", line 22, in <module>
    statuses = api.GetUserTimeline(TWITTER_USERNAME)
AttributeError: 'NoneType' object has no attribute 'GetUserTimeline'


Help solve the problem. In theory, the code should not require a key.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-06-22
@SoreMix

Where did you get the example code?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question