Problem with open-uri

Hi !

I'm unable to open certain URIs with open-uri. Here is the code :

  require 'rexml/document'
  require 'open-uri'
  xml = REXML::Document.new(open("http://myoms.net/soap/oms2.wsdl"))

The error I get is :

/usr/lib/ruby/1.8/rexml/parsers/baseparser.rb:133:in `stream=': Tempfile is not a valid input stream. It must be (RuntimeError)
either a String, IO, StringIO or Source.

I have tried to "cast" the parameter to IO with to_io, but it still doesn't work. Any ideas ?

David Sulc wrote:

Hi !

I'm unable to open certain URIs with open-uri. Here is the code :

  require 'rexml/document'
  require 'open-uri'
  xml = REXML::Document.new(open("http://myoms.net/soap/oms2.wsdl"\))

The error I get is :

/usr/lib/ruby/1.8/rexml/parsers/baseparser.rb:133:in `stream=': Tempfile
is not a valid input stream. It must be (RuntimeError)
either a String, IO, StringIO or Source.

ran that above code and it worked:
<?xml version='1.0' encoding='UTF-8'?>
<definitions name='OnlineMessengerService'
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/&#39;
xmlns:tns='uri://www.myoms.net/'
xmlns:soapenc='Error;
xmlns:s0='uri://www.myoms.net/types/'
xmlns:s='http://www.w3.org/2001/XMLSchema&#39;
targetNamespace='uri://www.myoms.net/'
xmlns='Error;
  <types>
    <s:schema elementFormDefault='qualified'
attributeFormDefault='qualified'
targetNamespace='uri://www.myoms.net/types/'>
      <s:complexType name='Time'>
        <s:sequence>
          <s:element maxOccurs='1' name='year' minOccurs='1'
nillable='false' type='s:long'/>
....

Maybe provide the actual code you are running, if it is not exaclty the
above.

Cheers

if it works on strings just do

open("http://myurl.com").read

···

On 1/12/07, David Sulc <davidsulc@gmail.com> wrote:

Hi !

I'm unable to open certain URIs with open-uri. Here is the code :

  require 'rexml/document'
  require 'open-uri'
  xml = REXML::Document.new(open("http://myoms.net/soap/oms2.wsdl&quot;\))

The error I get is :

/usr/lib/ruby/1.8/rexml/parsers/baseparser.rb:133:in `stream=': Tempfile
is not a valid input stream. It must be (RuntimeError)
either a String, IO, StringIO or Source.

I have tried to "cast" the parameter to IO with to_io, but it still
doesn't work. Any ideas ?

ChrisH wrote:

David Sulc wrote:
  

Hi !

I'm unable to open certain URIs with open-uri. Here is the code :

  require 'rexml/document'
  require 'open-uri'
  xml = REXML::Document.new(open("http://myoms.net/soap/oms2.wsdl&quot;\))

The error I get is :

/usr/lib/ruby/1.8/rexml/parsers/baseparser.rb:133:in `stream=': Tempfile
is not a valid input stream. It must be (RuntimeError)
either a String, IO, StringIO or Source.
    
ran that above code and it worked:
<?xml version='1.0' encoding='UTF-8'?>
<definitions name='OnlineMessengerService'
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/&#39;
xmlns:tns='uri://www.myoms.net/'
xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/&#39;
xmlns:s0='uri://www.myoms.net/types/'
xmlns:s='http://www.w3.org/2001/XMLSchema&#39;
targetNamespace='uri://www.myoms.net/'
xmlns='http://schemas.xmlsoap.org/wsdl/&#39;&gt;
  <types>
    <s:schema elementFormDefault='qualified'
attributeFormDefault='qualified'
targetNamespace='uri://www.myoms.net/types/'>
      <s:complexType name='Time'>
        <s:sequence>
          <s:element maxOccurs='1' name='year' minOccurs='1'
nillable='false' type='s:long'/>
....

Maybe provide the actual code you are running, if it is not exaclty the
above.
  

The code I run is different, however this simple example fails too.

What I really don't understand is that if I give a different URL (such as "http://www.webservicex.net/genericbarcode.asmx?wsdl&quot;\), it's OK.

The complete error stack trace is

/usr/lib/ruby/1.8/rexml/parsers/baseparser.rb:133:in `stream=': Tempfile is not a valid input stream. It must be (RuntimeError)
either a String, IO, StringIO or Source. from /usr/lib/ruby/1.8/rexml/parsers/baseparser.rb:100:in `initialize'
        from /usr/lib/ruby/1.8/rexml/parsers/treeparser.rb:8:in `initialize'
        from /usr/lib/ruby/1.8/rexml/document.rb:178:in `build'
        from /usr/lib/ruby/1.8/rexml/document.rb:45:in `initialize'
        from test.rb:3

When I reaserched this, all I was able to discover was that it seems to be a problem with Ruby's duck typing (http://community.livejournal.com/evan_tech/173207.html\) and/or REXML.

Any ideas ?

xml = REXML::Document.new(open("http://myoms.net/soap/oms2.wsdl&quot;\)*.read*)

Try that.

Dan

Gregory Brown wrote:

···

On 1/12/07, David Sulc <davidsulc@gmail.com> wrote:

Hi !

I'm unable to open certain URIs with open-uri. Here is the code :

  require 'rexml/document'
  require 'open-uri'
  xml = REXML::Document.new(open("http://myoms.net/soap/oms2.wsdl&quot;\))

The error I get is :

/usr/lib/ruby/1.8/rexml/parsers/baseparser.rb:133:in `stream=': Tempfile
is not a valid input stream. It must be (RuntimeError)
either a String, IO, StringIO or Source.

I have tried to "cast" the parameter to IO with to_io, but it still
doesn't work. Any ideas ?

if it works on strings just do

open("http://myurl.com").read

Daniel Finnie wrote:

xml = REXML::Document.new(open("http://myoms.net/soap/oms2.wsdl&quot;\)*.read*)

Try that.

Dan

That seems to work. I had tried, but apparently with the wrong syntax.

I have a few errors in my script, so I can really test it right now...

Thanks a lot !