question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

async invalid syntax

See original GitHub issue

I’m fairly new to coding—just taking a coding class this semester. I’m using a MacBook Air and downloaded PyCharm, and so far, I’ve been able to figure most things out, but I’m stuck on this one.

I’m trying to get the tweepy Stream Listener to return the tweets for a certain hashtag, and this code worked without issue on the Windows computers on campus. The code I’m running looks like this:

import tweepy
#override tweepy.StreamListener to add logic to on_status
class MyStreamListener(tweepy.StreamListener):

    def on_status(self, status):
        print(status.text)

    def on_error(self, status_code):
        if status_code == 420:
            # returning False in on_data disconnects the stream
            return False
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth, listener=myStreamListener)

myStream.filter(track=['#fakenews'])

On my computer, it returns this error:

Traceback (most recent call last): File “/Users/USERNAME/PycharmProjects/Homework/Twitter.py”, line 7, in <module> import tweepy File “/Users/USERNAME/PycharmProjects/Homework/venv/lib/python3.7/site-packages/tweepy/init.py”, line 17, in <module> from tweepy.streaming import Stream, StreamListener File “/Users/USERNAME/PycharmProjects/Homework/venv/lib/python3.7/site-packages/tweepy/streaming.py”, line 358 def _start(self, async): ^ SyntaxError: invalid syntax

The carat is actually under async, not at the beginning of the line. The last two “files” are the code from the tweepy module, not any code I’ve written or searched through.

I’ve tried changing the interpreter for my project in PyCharm, but I’m not sure what else to try. My professor looked at it and didn’t want to get into the backend code (and honestly, I don’t either, since I don’t really know what I’m doing), so I’m stuck as to what to try next or actually what the real issue is.

Any suggestions?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

38reactions
beinghorizontalcommented, May 9, 2018

The same issue but on Windows10 x64 python3.7 beta, on python3.6 it works fine, so seems like incompatibility with python 3.7? Okay found the solution. Apparently async cannot be used as an argument name in Python 3.7 So open streaming.py and replace #async with async_ it fixed the error for me.

16reactions
skidzocommented, Sep 25, 2018

this will stay an issue amongst users trying to pip install this package on python > 3.7(as there is no anaconda) when will you upload the fix?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python [Invalid syntax] with async def - Stack Overflow
I am trying write discord bots using Python, I have come across and threw together this bot. import discord import asyncio import random...
Read more >
Async def invalid syntax - Discussions on Python.org
Hello, today I copied bot from GitHub, but when I wanted to run that bot so it throw this error: File "/home/Bot/bot.py", line...
Read more >
Python 3.9 async def invalid syntax : r/learnprogramming
Yesterday i tried to program a discord music bot using the discord.py lib, for our server, but whenever i try to run the...
Read more >
Python Web App using "asyncio" not starting, has "invalid ...
After deploying the applications, it refuses to start with an "invalid syntax" error within the standard "asyncio" library.
Read more >
Python 3.7 syntax error: async is a reserved keyword #4849
Python 3.7 syntax error: async is a reserved keyword #4849 ... line 22 from . import async, base ^ SyntaxError: invalid syntax.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found