我該如何處理?UnicodeEncodeError:'cp949'編解碼器無法編碼字符
wfile.write(數據[ '文本'] + '\ N')
UnicodeEncodeError: 'CP949' 編解碼器無法編碼的字符
import tweepy
import time
import os
import json
search_term1 = ''
search_term2 = ''
lat = ""
lon = ""
radius = ""
location = "%s,%s,%s" % (lat, lon, radius)
auth = tweepy.OAuthHandler(API_key, API_secret)
auth.set_access_token(Access_token, Access_token_secret)
api = tweepy.API(auth)
c=tweepy.Cursor(api.search,
q="{}+OR+{}".format(search_term1, search_term2),
rpp=1000,
geocode=location,
include_entities=True)
wfile = open(os.getcwd()+"/test1.txt", mode='w')
data = {}
i = 1
for tweet in c.items():
data['text'] = tweet.text
print(i, ":", data)
wfile.write(data['text']+'\n')
time.sleep(0.5)
i += 1
wfile.close()
我通過修改因特網得到這個錯誤。
類型錯誤:寫()不帶任何關鍵字參數
wfile.write(data['text']+'\n',encoding='UTF8')
類型錯誤:寫()接受只有一個參數(2給出)
wfile.write(data['text']+'\n','utf-8')