Rails: Net::OpenTimeout execution expired with HTTParty - ruby-on-rails

My app is supposed to get JSON data from an external URL. It was working just fine until this morning. I see this error message:
Net::OpenTimeout in CommandesController#generate
execution expired
I have changed NOTHING and I can still access the external json url from a browser. Can you please help me ?
Here is the code that creates the issue:
#data = HTTParty.get(URL).parsed_response

The external site may be causing the timeouts. Try increasing the timeout period.
#data = HTTParty.get(URL, timeout: 60).parsed_response

I had the same problem, with this error raising occasionally. What helped was to:
require 'resolv-replace'
Looks like it's was an issue with how Ruby resolves DNS.

I Solve the issue by adding verify:true to HTTParty so that it forces SSL acceptation
#data = HTTParty.get(URL, verify:true).parsed_response

Related

Yelp Place API returning "Invalid Signature" Error only from Nginx on EC2

Problem: I am getting an "Invalid Signature" error from Yelp API only from production (running on nginx server in AWS) When I run locally on my localhost:3000, there is no signature error, and everything works fine.
I am using the yelp gem in rails. Here's some code in ruby.:
$client = Yelp::Client.new({
consumer_key: $SL_CONSUMER_KEY,
consumer_secret: $SL_CONSUMER_SECRET,
token: $SL_TOKEN,
token_secret: $SL_TOKEN_SECRET
})
begin
$client.search("Los Angeles")
rescue => error
puts error.message
puts error.inspect
end
error.message prints out: "Signature was invalid"
error.inspect prints out: < Yelp::Error::InvalidSignature: Signature was invalid >
Everything works when I run locally on rails' Webrick server but when I run it in production, I get an "Invalid Signature" error.
Has anyone seen this? I've looked at some relevant posts, but this seems different. Thanks!
This will probably not pertain to most people, but the off chance it could help someone, here it is:
My "time" was effed up on my EC2 instance. So for example, in ruby, Time.now was not printing the actual time. (I think it was off by a few minutes or so).
Anyway, Yelp API requires a oauth_timestamp when you send a request. Of course, then, my request was timing out b/c the time was off.
How did I found this error out?
I just pinged the URL on my browser with the oauth, token, oauth_timestamp, etc. (few more) as query params. The browser spits out the error response in JSON, and it was saying that my request was timing out. When you use the ruby Yelp Client and catch the exception in code, it doesn't spit out the error response in terminal, so it's a bit more difficult to locate the exact root of the error.
How I solved it:
I re-calibrated the time in my ec2 instance by following the directions here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html
Problem is solved. Peace.
Invalid signature error in Yelp API occurs due to two reasons .
First , Either of your four keys i.e consumer_key , consumer_secret_key , Token & Token Secret is invalid . Secondly Parameters passed to Yelp API Function are either invalid or any of those are nil .

Possible Attack autoshell.txt

I got this error reported to me recently from my Rails app.
mycontroller#update (ArgumentError) "invalid %-encoding (<%MYTEST)
An ArgumentError occurred in mycontroller#update:
invalid %-encoding (<%MYTEST)
These are the parameters that were passed.
Parameters : {"controller"=>"mycontroller", "action"=>"update", "id"=>"autoshell", "format"=>"txt"}
Should I be worried? I recently upgraded to Rails 4.1 and ruby 2.1.3. What is autoshell.txt?
This seems to be somebody scanning for websites vulnerable to JCE Joomla Extension Auto Shell Upload Exploit. Really nothing to worry about.
I've been seeing this error in our logs as well. I'm not concerned about it personally, but if it becomes annoying you can add this to your routes.rb file:
put '/autoshell', to: proc { [404, {}, ['']] }
That will return an empty 404 response.

Jasper server integration in rails 2

I want to configure jasperserver-client gem in order to receive reports from Jasper server through SOAP.
The error I get is JasperServer::Error: JasperServer replied with an error: exception getting data strategy
after running the following from console:
client = JasperServer::Client.new("http://example.com/jasperserver-pro/services/repository", "jasperadmin", "jasperadmin")
request = JasperServer::ReportRequest.new("/public/test2", "PDF", { 'last_login_at' => '2013-01-15 00:00:00'})
pdf_data = client.request_report(request)
Any idea what might be the cause. I think that it's able to find the server and the report but it might be something wrong with the optional parameters.
I also tried generating the request without the option hash
I've solved my problem with this tutorial
http://jonif.blogspot.com.br/2012/07/

koala response times. 20 seconds waiting response

I'm new with Rubyonrails and Koala gem and I'm sure I'm doing something wrong. I've been tuning my code to the minimun expression but the problem persist. Then I tried to do the same without koala gem, but the problem persisted.
This is the code:
require 'koala'
require 'open-uri'
puts Time.now
#graph = Koala::Facebook::API.new
resp = #graph.graph_call("cocacola", {}, "get", {})
puts resp
puts Time.now
coke_url = "https://graph.facebook.com/cocacola"
response = open coke_url
response = JSON.parse response.read
puts response.inspect
puts Time.now
I have to wait always 21 seconds the Facebook's response. If I put the https://graph.facebook.com/cocacola on my browser, the response is instantaneous ¿is not the same?
thanks
I'm using Koala in my application and did not have such experience. The only difference is that I don't use it anonymously. Instead I created an app and I'm using an access token to access the Facebook API. This might be the root cause, as I've found this post that also seems relates.
Finally, it was a DNS problem (thanks jpgeek).
When I did just a GET request to any website, the response was after 21 seconds, but using the IP of the same website, the response was instantaneously.
I found on google the solution: http://www.mikeperham.com/2010/02/10/asynchronous-dns-resolution/
I have use this personal solution in Gemfile (I'm not sure if it's the best):
group :development do
require 'resolv'
require 'resolv-replace'
end
Now it's working fine!

(#803) Some of the aliases you requested do not exist: access_token","type":"OAuthException"

I am trying to get access token using from facebook graph API in my rails 2.3 based web application. The request I am sending for that is :
https://graph.facebook.com/oauth/access_token?client_id=<client_id>
&redirect_uri=http://localhost:3001/facebook_callback
&client_secret=<client_secret>
&code=AQBgog2NvoUYQCXsa2bGpj--s9RD71F3zTKX344cUZ-
AWX4CNhdx3Yerl_wmzQkQ4zIUFVS_CRoN0zXaEW63dHcC9sH6_
vl7ljSxwA6TLSrkWVcfdfdrmwBTlMNIzyJr0h6irGW1LCdTw8
Racgd8MQ9RgVn1gFL26epWA
And it is redirecting me to
http://localhost/facebook_callback?code=AQBgog2NvoUYQCXsa2bGpj--
s9RD71F3zTKX344cUZ AWX4CNhdx3Yerl_wmzQkQ4zIUFVS_CRoN0mAB_Sr1H4K
dXIlzXaEW63dHcC9sH6_vl7ljSxwA6TLSrkWVcfdfdrmwBTlMNIzyJr0h6irG
SxsrRAXtdviNsBTMW1LCdTw8Racgd8MQ9RgVn1gFL26epWA
I am getting error in both development and production environment . I am not able to get the access token. Has anyone else face the problem ??
This looks correct - Facebook redirects to your redirect url with the code= parameter. You then need to exchange the code for an access token. See here: http://developers.facebook.com/docs/authentication/
edit: my bad, I misread the first section. You can sometimes have problems using localhost as a redirect. Are you using a live domain without port in your non-test environment?
Well, I found solution of my problem :
The problem was with the path which I was using for request of access_token . I placed a slash in front of the path and bingo. It worked like a charm.
So instead of
oauth/access_token?client_id=#{ #client_id }&redirect_uri=#{ #redirect_uri }&client_secret=#{ #client_secret }&code=#{ code }"
we just need to use
/oauth/access_token?client_id=#{ #client_id }&redirect_uri=#{ #redirect_uri }&client_secret=#{ #client_secret }&code=#{ code }".
Thanks to all people for your efforts.

Resources