簡體   English   中英

語法錯誤:連接到wallaroo時語法無效

[英]syntaxError: Invalid syntax when connecting to wallaroo

我在運行twitter_client.py時遵循了本教程“ https://blog.wallaroolabs.com/2017/11/identifying-trending-twitter-hashtags-in-real-time-with-wallaroo/ ”,但出現此錯誤:

文件“ twitter_client.py”,行44打印(在%s:%s上連接到Wallaroo)%(wallaro_input_address)語法錯誤:無效的系統稅。

這是代碼

import socket
import sys
import requests
import requests_oauthlib
import json

# Replace the values below with yours
ACCESS_TOKEN = ''
ACCESS_SECRET = ''
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
my_auth = requests_oauthlib.OAuth1(CONSUMER_KEY, 
CONSUMER_SECRET,ACCESS_TOKEN, ACCESS_SECRET)
def send_tweets_to_wallaroo(http_resp, tcp_connection):
for line in http_resp.iter_lines():
try:
full_tweet = json.loads(line)
if 'text' in full_tweet:
tweet_text = full_tweet['text'].encode('utf-8')
# send the length of text + 1 for newline represented as 5 ASCII
# characters, followed by the tweet text and \n
# e.g. if tweet text is 'Hello everyone!', send '00016Hello everyone!'
tcp_connection.sendall(str(len(tweet_text)+1).zfill(5) +
tweet_text + '\n')
except:
print ("Error decoding data received from Twitter!")
def get_tweets():
url = 'https://stream.twitter.com/1.1/statuses/filter.json'
query_data = [('locations', '-130,-20,100,50'), ('track', '#')]
query_url = url + '?' + '&'.join([str(t[0]) + '=' + str(t[1]) for t in 
query_data])
response = requests.get(query_url, auth=my_auth, stream=True)
return response
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Connect to Wallaroo
wallaro_input_address = ('localhost', 8002)

print (connecting to Wallaroo on %s:%s) % (wallaro_input_address)
sock.connect(wallaro_input_address)

resp = get_tweets()
send_tweets_to_wallaroo(resp,sock)

請幫助...謝謝

嘗試使用此行而不是第44行:

print('connecting to Wallaroo on %s:%s' % (wallaro_input_address))

在python3中格式化的另一種方式:

print('connecting to Wallaroo on {}'.format(wallaro_input_address))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM