I am trying to stream arabic tweet from an api twitter with python
up vote
1
down vote
favorite
class listener(StreamListener):
def on_data(self, data):
try:
tweet=data
t=tweet.encode('utf-8').decode('unicode_escape')
print(t)
saveFile = open('E:\da.json','a')
saveFile.write(t)
saveFile.write('n')
saveFile.close()
return True
except BaseException as e:
print ('failed on data',str(e))
time.sleep(5)
def on_error(self,status):
print (status)
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=['رياضه'],languages=["ar"])
The error appears is:
failed on data 'utf-8' codec can't encode character 'ud83d' in
position 2808: surrogates not allowed and continues to download the
data
how I can solve it can anyone help me.
the program print the text in Arabic but when load it with the next program.
with io.open('E:\da.json', 'r',encoding ='utf-8') as f:
line = f.readline()
tweets = json.loads(line)
print(tweets)
The error :
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe5 in position
111: invalid continuation byte
python-3.x
add a comment |
up vote
1
down vote
favorite
class listener(StreamListener):
def on_data(self, data):
try:
tweet=data
t=tweet.encode('utf-8').decode('unicode_escape')
print(t)
saveFile = open('E:\da.json','a')
saveFile.write(t)
saveFile.write('n')
saveFile.close()
return True
except BaseException as e:
print ('failed on data',str(e))
time.sleep(5)
def on_error(self,status):
print (status)
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=['رياضه'],languages=["ar"])
The error appears is:
failed on data 'utf-8' codec can't encode character 'ud83d' in
position 2808: surrogates not allowed and continues to download the
data
how I can solve it can anyone help me.
the program print the text in Arabic but when load it with the next program.
with io.open('E:\da.json', 'r',encoding ='utf-8') as f:
line = f.readline()
tweets = json.loads(line)
print(tweets)
The error :
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe5 in position
111: invalid continuation byte
python-3.x
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
class listener(StreamListener):
def on_data(self, data):
try:
tweet=data
t=tweet.encode('utf-8').decode('unicode_escape')
print(t)
saveFile = open('E:\da.json','a')
saveFile.write(t)
saveFile.write('n')
saveFile.close()
return True
except BaseException as e:
print ('failed on data',str(e))
time.sleep(5)
def on_error(self,status):
print (status)
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=['رياضه'],languages=["ar"])
The error appears is:
failed on data 'utf-8' codec can't encode character 'ud83d' in
position 2808: surrogates not allowed and continues to download the
data
how I can solve it can anyone help me.
the program print the text in Arabic but when load it with the next program.
with io.open('E:\da.json', 'r',encoding ='utf-8') as f:
line = f.readline()
tweets = json.loads(line)
print(tweets)
The error :
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe5 in position
111: invalid continuation byte
python-3.x
class listener(StreamListener):
def on_data(self, data):
try:
tweet=data
t=tweet.encode('utf-8').decode('unicode_escape')
print(t)
saveFile = open('E:\da.json','a')
saveFile.write(t)
saveFile.write('n')
saveFile.close()
return True
except BaseException as e:
print ('failed on data',str(e))
time.sleep(5)
def on_error(self,status):
print (status)
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=['رياضه'],languages=["ar"])
The error appears is:
failed on data 'utf-8' codec can't encode character 'ud83d' in
position 2808: surrogates not allowed and continues to download the
data
how I can solve it can anyone help me.
the program print the text in Arabic but when load it with the next program.
with io.open('E:\da.json', 'r',encoding ='utf-8') as f:
line = f.readline()
tweets = json.loads(line)
print(tweets)
The error :
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe5 in position
111: invalid continuation byte
python-3.x
python-3.x
edited Dec 1 at 11:16
Banghua Zhao
1,136617
1,136617
asked Nov 8 at 14:11
esraa
613
613
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53209502%2fi-am-trying-to-stream-arabic-tweet-from-an-api-twitter-with-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown