0

I'm working on my first program in python using cloud9 where I connect to twitter API and do sentiment analysis, but when I run the code I get this problem:

Your code is running at https://x-x.c9users.io.
Important: use os.getenv(PORT, 8080) as the port and os.getenv(IP, 0.0.0.0) as the host in your scripts!

  File "/home/ubuntu/workspace/demo.py", line 23
SyntaxError: Non-ASCII character '\xd8' in file /home/ubuntu/workspace/demo.py on line 23, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

This is my code after I looked on a few solutions but I still get the same problem:

import os
import tweepy
from textblob import TextBlob

port = os.getenv('PORT', '8080')
host = os.getenv('IP', '0.0.0.0')

# Step 1 - Authenticate
consumer_key= 'xx'
consumer_secret= 'xx'

access_token='xx'
access_token_secret='xx'

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

#Step 3 - Retrieve Tweets
public_tweets = api.search('school')

for tweet in public_tweets:

    print(tweet.text)
    analysis = TextBlob(tweet.text)
    print(analysis.sentiment)
    print("")

I also tried something called "Flask" but nothing changed. Thank you

user8423460
  • 125
  • 2
  • 12
  • The error is quite clear - line 23 in `demo.py` has a non-ascii character in it. Have a look at the file and either set an encoding, or fix the character to be ascii. – match Jan 27 '18 at 20:38
  • Thank you, I fixed it. but I still get the same problem about the port – user8423460 Jan 27 '18 at 20:44
  • That looks informational, not like an error. I believe it's saying that if you want to run your code as a server and connect to it - this is how you determine what port and address it will be able to listen on. – match Jan 27 '18 at 20:49
  • Yes thank you! I think I got what is the problem :) – user8423460 Jan 27 '18 at 21:02

0 Answers0