Closed kares closed 1 year ago
an older version of the gem (5.15.0 + http.rb 0.9.9) seems to be working, proxy log:
2020/10/05 11:54:47.807 kid1| 11,2| client_side.cc(1302) parseHttpRequest: HTTP Client local=127.0.0.1:3128 remote=127.0.0.1:58600 FD 11 flags=1
2020/10/05 11:54:47.807 kid1| 11,2| client_side.cc(1303) parseHttpRequest: HTTP Client REQUEST:
---------
POST https://stream.twitter.com/1.1/statuses/filter.json?track=xxx HTTP/1.1
Authorization: OAuth oauth_consumer_key="...", oauth_nonce="...", oauth_signature="...", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1601891687", oauth_token="...", oauth_version="1.0"
Host: stream.twitter.com
User-Agent: http.rb/0.9.9
----------
2020/10/05 11:54:48.274 kid1| 11,3| http.cc(2310) httpStart: POST https://stream.twitter.com/1.1/statuses/filter.json?track=London,Barcelona
2020/10/05 11:54:48.275 kid1| 11,2| http.cc(2266) sendRequest: HTTP Server local=192.168.0.25:46560 remote=199.16.156.200:443 FD 14 flags=1
2020/10/05 11:54:48.275 kid1| 11,2| http.cc(2267) sendRequest: HTTP Server REQUEST:
---------
POST /1.1/statuses/filter.json?track=xxx HTTP/1.1
Authorization: OAuth oauth_consumer_key="...", oauth_nonce="59e85cfa31e58cb41085595bb3688f74", oauth_signature="...", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1601891687", oauth_token="...", oauth_version="1.0"
User-Agent: http.rb/0.9.9
Host: stream.twitter.com
Via: 1.1 precision (squid/4.10)
X-Forwarded-For: 127.0.0.1
Cache-Control: max-age=0
Connection: keep-alive
----------
the only difference seems to be
and sending a full URL: Content-Length: 0
POST https://stream.twitter.com/1.1/statuses/filter.json?track=xxx HTTP/1.1
:green_salad: confirmed, patching HTTP to send full URIs via proxy seems to resolve the issue:
(note that to connect to twitter's streaming API we're using https://
)
::HTTP::Request.class_eval do
def headline
request_uri =
if using_proxy? #&& !uri.https?
uri.omit(:fragment)
else
uri.request_uri
end
"#{verb.to_s.upcase} #{request_uri} HTTP/#{version}"
end
end
... the patch essentially undoes: https://github.com/httprb/http/pull/333 (which has been shipped since http.rb 2.0.0)
to recap, this is a (squid) proxy issue (https://github.com/httprb/http/pull/333 seems legit), still, annoying that things got broken with various proxies out there in the 6.x/7.0 line ...
Working through a proxy, I get an error: cannot interpret as DNS name: nil (gem 'twitter' 7.0.0). Reproduce:
def twi_sclient(t)
Twitter::Streaming::Client.new config(t)
end
def config(t)
{
consumer_key: t.key,
consumer_secret: t.secret,
access_token: t.token,
access_token_secret: t.token_secret,
proxy: proxy(t)
}
end
def proxy(t)
{
host: t.host,
port: t.port,
username: t.username,
password: t.password
}
end
[ActiveJob] [RetweetsJob] [d564b4c5-6f04-4191-bd69-bba02a4965e0] Error performing RetweetsJob (Job ID: d564b4c5-6f04-4191-bd69-bba02a4965e0) from Async(default) in 15.55ms: ArgumentError (cannot interpret as DNS name: nil)
Any ideas? Thank you.
I've tried setting up a proxy with the streaming client and it does not work, sample script:
Have tested this setup using twitter gem 6.2.0 as well as latest (7.0.0) on MRI 2.5.7 and JRuby 9.2.
Believe the problem might be with the http gem, potentially not handling the proxy setup for streaming connection? I was able to verify the proxy isn't an issue, I've tried Python's (tweepy) client with a similar setup using a proxy. The proxy is a standard Squid installation on ubuntu, listening on its default 3128 port.
The Ruby client seems to be trying a
POST
request for streaming which gets rejected:While the Python client simply issues a
CONNECT
:Also the proxy settings are bit confusing as they're different based on the client being used. Which is a shame considering most of the configuration is the same for both the rest and streaming client: