I used to have the following call working just fine on a Rails app running Ruby 1.8.7:
HTTParty.post("my uri", :body => "some body", :headers => { "Content-type" => "text/xml"})
When I run the same line on Ruby 1.9.2 I'm getting a MultiXml::ParseError with this message:
"xmlns: URI xyz is not absolute"
The call to my uri works just fine when I use curl, and I get back the expected response, which looks something like this:
<client login="foo" numsessions="1" xmlns="xyz"/>
Any Insight?
After much struggle, I gave up on HTTParty for this. I tried Patron, which worked local, but didn't on Heroku, and I finally settled on RestClient, which worked great. https://github.com/archiloque/rest-client
That's because curl doesn't try to parse the xmlns. You could either try making sure you use the same version of httparty with 1.9.2 as you use with 1.8.7 or asking the people in charge of that uri to make the xmlns valid
Related
I've been stuck with this for about two days...
I use ruby(version 2.3.3p222) gem rest-client(v2.0.0) to send a GET request with a ipv6 url to the server (Apache/2.2.31):
url = 'https://[fd36:4928:8040:dc10:0000:0000:0000:0160]:8080/resources/1'
resource = RestClient::Resource.new(url, :ssl_version => 'TLSv1', :verify_ssl => false, :headers => {'Authorization' => 'Basic cm9vdDAbCdEfwYXNzMSE='})
resource.get
I got a 400 bad response and the body says:"Your browser sent a request that this server could not understand. Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request"
However I can use curl command with the same parameters and get the right response, so I suspect maybe it's something wrong with the header of my rest-client request.
PS: I also tested with adding the 'host'
header: {'Authorization' => 'Basic cm9vdDAbCdEfwYXNzMSE=', 'host' => '[fd36:4928:8040:dc10:0000:0000:0000:0160]:8080' }
It still failed with the same bad response.
I just noticed the appache error for this request, it says:
"httpd[29124]: [error] Hostname fd36:4928:8040:dc10:0000:0000:0000:0160 provided via SNI and hostname fd36:4928:8040:dc10:0000:0000:0000 provided via HTTP are different
"
The curl command you supplied would translate --user admin:password into the following header:
Authorization: Basic YWRtaW46cGFzc3dvcmQ=
However, you're sending
Basic: cm9vdDAbCdEfwYXNzMSE=
which is not the same thing... so the server is probably complaining about not getting the correct auth...
After debugging and googling for another day, this problem seems to be clear:
From a similar bug report to chrome https://bugs.chromium.org/p/chromium/issues/detail?id=500981, "SNI is only hostnames, and should never contain IPs.". However ruby does use ip as hostname (in this case rest-client is nothing to blame since it just delegate everything down to ruby lib). You can find evidence in Net::HTTP#connect (around line 922):
# Server Name Indication (SNI) RFC 3546
s.hostname = #address if s.respond_to? :hostname=
Just comment out the last line it will work (to workaround this you have to do a monkey patch). Additionally, as pointed out by #alberge, host header does not contain brackets, the final request host header is like this: "FD36:4928:8040:DC10::162", no "[ ]" around.
Also on Apache side, it does something wrong since it just strips off everything from the last colon to get the host name without any extra check- this still exists in version 2.4.10, not sure if it is fixed or not.
This appears to be either a bug in rest-client or a regression in Ruby Net::HTTP.
https://github.com/rest-client/rest-client/issues/583
What version of Ruby are you using? Have you tried using Ruby 2.1 to see if it works there?
EDIT:
This is Ruby Bug #12642. The Host header for an IPv6 address is sent with no enclosing [ ].
Ruby in 2.1.6 - 2.1.10 doesn't have the bug, but versions >= 2.2.0 are affected.
And worse still, there's a bug with setting an explicit IPv6 Host header so you get an exception URI::InvalidComponentError: bad component(expected host component): [
I'm using the twitter gem found here: http://sferik.github.io/twitter/
I have some code that looks like:
#twitter_client.update(tweet_string, :in_reply_to_status_id => 402712877960019968)
Which generates the error:
./twitter.rb:68:in `update': wrong number of arguments (2 for 1) (ArgumentError)
However, I'm looking at the documentation here: https://github.com/sferik/twitter/blob/master/examples/Update.md
Which says:
client.update("I'm tweeting with #gem!", :in_reply_to_status_id => 402712877960019968)
When I remove the :in_reply_to_status_id, it works fine. I believe you can see the method here (Line 128): https://github.com/sferik/twitter/blob/0d23c5ed65a7e7728cd096d611e5edeecdbc6e79/lib/twitter/rest/tweets.rb
Any thoughts on what I'm doing wrong here?
I got it to work using the latest gem version and putting the in reply status in a hash:
client.update("I'm tweeting with #gem!", {:in_reply_to_status_id => 402712877960019968})
Give that a try and let me know if that works
I am having issues using the rt-client gem(link), as it keeps returning a "RT/4.0.8 401 Credentials Required". The REST interface for this site is working, as I have some perl scripts that are currently working with it in a similar fashion.
test.rb
#!/usr/bin/env ruby
require 'rt/client'
rt = RT_Client.new
id = rt.create( :Queue => "General",
:Subject => "Test",
:Requestor => "test#example.org",
:Text => "Ignore me"
)
.rtclientrc
server=http://example.org/
user=exampleuser
pass=examplepass
cookies=tmp
Versions
Gem Version: rt-client-0.5.0
RT Version: 4.0.8
Ruby Version: 1.9.3p327
Output
Payload for new ticket:
------xYzZY492386xYzZY
Content-Disposition: form-data; name="content";
Queue: General
Subject: Test
Requestor: test#example.org
Text: Ignore me
id: ticket/new
------xYzZY492386xYzZY--
"RT/4.0.8 401 Credentials required\n"
I am seeing the error when I do a "puts id.inspect" at the bottom of test.rb, as the ticket is not getting created.
Is this perhaps an issue with the handling of cookies? I was trying to avoid writing a custom solution in Net::HTTP if possible, but I will go that route if this continues to be a hassle.
Author of the rt-client ruby gem here.
This was resolved some time ago and I know this is old, but it is ranked highly in a Google search for the gem. If anyone finding this question still has issues with rt-client, the gem is now on github.com. If you wish, please clone it, make your fix and send me a pull request.
https://github.com/uidzip/rt-client
I'm trying to initialize a variable called proxy like this:
proxy = Savon::Client.new "http://192.168.1.1:8080"
The thing is, when I run my code, I only get the error:
NameError: uninitialized constant NameOfTheClass::Savon
Thanks for any help!
PD: I'm using Ruby 1.9.2
PD2: I'm trying to run this from console.
You found probably the documentation for versions < 0.8.x.
Unfortunately the syntax has changed! Have a look here: https://github.com/rubiii/savon/blob/master/README.md
Savon works with blocks now.
Your example should now look like this
require 'savon'
require 'pp'
proxy = Savon::Client.new do
wsdl.document = "http://my.webservices.net/service?wsdl"
end
pp proxy.wsdl.soap_actions
(GAVE UP ON INSTALLING CURB. POSTED NEW QUESTION PER SUGGESTION OF ONE OF THE RESPONDENTS)
I thought 'curl ' was 'built-in' but got an undefined method error in a sinatra app. is there a gem i need to add?
Same question for rails 3?
The application is that I have to simply 'hit' an external url (http://kickstartme.someplace.com?action=ACTIONNAME&token=XYZXYZXYZ) to kickstart a remote process.
the external url returns XML describing success/failure in the format:
<session>
<success>true</success>
<token>xyzxyzxyz</token>
<id>abcabcabc</id>
</session>
So really, ALL I need is for my rails and sinatra apps to hit that url and parse whatever is returned AND grcefully handle the remote server failing to reply.
require 'open-uri'
require 'nokogiri'
response = open("http://kickstartme.someplace.com?action=ACTIONNAME&token=XYZXYZXYZ").read
doc = Nokogiri::XML(response)
Use curb, a Ruby binding to libcurl. You will get all the curl features without having to shell out with system.
curl -b "auth=abcdef; ASP.NET_SessionId=lotsatext;" example.com
turns into
curl = Curl::Easy.new('http://example.com/')
curl.cookies = 'auth=abcdef; ASP.NET_SessionId=big-wall-of-text;'
curl.perform
More curb examples