Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty loop in get_remote_tweets leads to error (variable referenced before assignment) #110

Closed
kdave opened this issue Mar 7, 2016 · 11 comments
Assignees
Milestone

Comments

@kdave
Copy link
Contributor

kdave commented Mar 7, 2016

> twtxt timeline
Traceback (most recent call last):
  File "/usr/bin/twtxt", line 9, in <module>
    load_entry_point('twtxt==1.2.1', 'console_scripts', 'twtxt')()
  File "/usr/lib/python3.4/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.4/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.4/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3.4/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.4/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3.4/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/lib/python3.4/site-packages/twtxt/cli.py", line 126, in timeline
    tweets = get_remote_tweets(sources, limit, timeout, cache)
  File "/usr/lib/python3.4/site-packages/twtxt/twhttp.py", line 123, in get_remote_tweets
    return tweets
UnboundLocalError: local variable 'tweets' referenced before assignment

This started after I added a few new follow urls, I don't know which one does that, will try to find out.

@kdave
Copy link
Contributor Author

kdave commented Mar 7, 2016

Running directly from git:

2016-03-07 14:36:39,680 asyncio      ERROR    Unclosed response
client_response: <ClientResponse(https://twtxt.xvm.space/) [None None]>
None

@kdave
Copy link
Contributor Author

kdave commented Mar 7, 2016

https://twtxt.xvm.space/ appears in the failed request, but removing it from the config still produces the same error.

@kdave
Copy link
Contributor Author

kdave commented Mar 7, 2016

I've iterated 'twtxt view' over all my follows and it points to ... @mdom ! (https://mdom.github.io/twtxt.txt)

@mdom
Copy link
Contributor

mdom commented Mar 7, 2016

I added a comment line yesterday that seemed to be the culprit. It worked for @kdave after i removed the line... :)

@buckket buckket added the bug label Mar 7, 2016
@buckket buckket added this to the 1.3.0 milestone Mar 7, 2016
@buckket
Copy link
Owner

buckket commented Mar 30, 2016

@mdom Do you still know which line caused the error? Trying to reproduce this so I can catch the exception which leads to this.

@mdom
Copy link
Contributor

mdom commented Mar 30, 2016

This was my first experiment with comments: A hash sign at the beginning of a line. I think this line crashed twtxt.

@buckket
Copy link
Owner

buckket commented Mar 30, 2016

I’m not able to reproduce this with 1.3.0dev.

@kdave
Copy link
Contributor Author

kdave commented Mar 30, 2016

I can see the same crash with current master (5cb114f), try on this url: https://kdave.github.io/twtxt-test.txt

@buckket
Copy link
Owner

buckket commented Mar 30, 2016

Very strange, I get this:
twtxt.parser DEBUG https://kdave.github.io/twtxt-test.txt - Unknown string format

But no exception, twtxt continues processing the other sources and tweets, as intended.

Can you provide the --verbose output?

@buckket buckket added the waiting label Apr 2, 2016
@buckket buckket self-assigned this Apr 2, 2016
@kdave
Copy link
Contributor Author

kdave commented Apr 4, 2016

top commit 2b31ad3

$ twtxt -v view https://kdave.github.io/twtxt-test.txt
2016-04-04 10:27:04,956 twtxt.cli    DEBUG    Not following https://kdave.github.io/twtxt-test.txt, trying as URL
2016-04-04 10:27:04,958 asyncio      DEBUG    Using selector: EpollSelector
2016-04-04 10:27:04,959 asyncio      DEBUG    poll 0.000 took 0.000 seconds
2016-04-04 10:27:04,959 asyncio      DEBUG    poll 0.000 took 0.000 seconds
2016-04-04 10:27:04,962 asyncio      DEBUG    poll 0.000 took 0.000 seconds
2016-04-04 10:27:04,983 asyncio      DEBUG    poll 4.998 took 0.019 seconds
2016-04-04 10:27:04,983 asyncio      DEBUG    poll 0.000 took 0.000 seconds
2016-04-04 10:27:04,984 asyncio      DEBUG    poll 4.979 took 0.000 seconds
2016-04-04 10:27:04,984 asyncio      DEBUG    poll 0.000 took 0.000 seconds
2016-04-04 10:27:04,984 asyncio      DEBUG    poll 0.000 took 0.000 seconds
2016-04-04 10:27:05,008 asyncio      DEBUG    poll 4.978 took 0.024 seconds
2016-04-04 10:27:05,008 asyncio      DEBUG    poll 0.000 took 0.000 seconds
2016-04-04 10:27:05,035 asyncio      DEBUG    poll 4.953 took 0.026 seconds
2016-04-04 10:27:05,063 asyncio      DEBUG    poll 4.923 took 0.024 seconds
2016-04-04 10:27:05,064 asyncio      DEBUG    poll 0.000 took 0.000 seconds
2016-04-04 10:27:05,064 asyncio      DEBUG    poll 0.000 took 0.000 seconds
2016-04-04 10:27:05,064 asyncio      DEBUG    poll 0.000 took 0.000 seconds
2016-04-04 10:27:05,064 asyncio      DEBUG    poll 0.000 took 0.000 seconds
2016-04-04 10:27:05,065 asyncio      DEBUG    poll 0.000 took 0.000 seconds
2016-04-04 10:27:05,090 asyncio      DEBUG    poll took 0.025 seconds
2016-04-04 10:27:05,090 asyncio      DEBUG    poll 0.000 took 0.000 seconds
2016-04-04 10:27:05,095 asyncio      DEBUG    poll 0.000 took 0.000 seconds
2016-04-04 10:27:05,096 asyncio      DEBUG    poll 0.000 took 0.000 seconds
2016-04-04 10:27:05,096 asyncio      DEBUG    poll 0.000 took 0.000 seconds
Traceback (most recent call last):
  File "/usr/bin/twtxt", line 9, in <module>
    load_entry_point('twtxt==1.3.0.dev0', 'console_scripts', 'twtxt')()
  File "/usr/lib/python3.4/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.4/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.4/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3.4/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.4/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3.4/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/lib/python3.4/site-packages/twtxt/cli.py", line 195, in view
    ctx.forward(timeline)
  File "/usr/lib/python3.4/site-packages/click/core.py", line 552, in forward
    return self.invoke(cmd, **kwargs)
  File "/usr/lib/python3.4/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3.4/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/lib/python3.4/site-packages/twtxt/cli.py", line 155, in timeline
    tweets = sort_and_truncate_tweets(tweets, sorting, limit)
UnboundLocalError: local variable 'tweets' referenced before assignment

@buckket
Copy link
Owner

buckket commented Apr 6, 2016

Okay, using the same version with the exact same arguments I get:

$ twtxt -v view https://kdave.github.io/twtxt-test.txt
2016-04-06 15:28:35,265 twtxt.cli    DEBUG    Not following https://kdave.github.io/twtxt-test.txt, trying as URL
2016-04-06 15:28:35,290 asyncio      DEBUG    Using selector: EpollSelector
2016-04-06 15:28:35,576 twtxt.parser DEBUG    https://kdave.github.io/twtxt-test.txt - Unknown string format
2016-04-06 15:28:35,576 twtxt.twhttp DEBUG    https://kdave.github.io/twtxt-test.txt returned 200 and Last-Modified header - adding content to cache

➤ https://kdave.github.io/twtxt-test.txt (27 days ago):
fc6c8cdfe580 btrfs-progs: check: unify naming of long option values / David Sterba

I guess it has something to do with twtxt’s dependencies or even the Python version in use.
I’ve tested it successfully with Python 3.4.4 and Python 3.5.1.

It worked with these dependencies installed:

aiohttp==0.21.5
chardet==2.3.0
click==6.6
coverage==4.0.3
humanize==0.5.1
pluggy==0.3.1
py==1.4.31
pytest==2.9.1
pytest-cov==2.2.1
python-dateutil==2.5.2
six==1.10.0
tox==2.3.1
virtualenv==15.0.1

@buckket buckket closed this as not planned Won't fix, can't repro, duplicate, stale Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants