open-uri and can't convert Hash into String

I'm posting this in hopes that search engines grab it and put it at the top of their list when other poor soul's run into this problem.

If you're trying to grab a web resource using Open-URI, and you are using basic authentication (username/password) then you'll need to make sure to require 'open-uri' or you'll get:

open("", :http_basic_authentication => ["username", "password"])
TypeError: can't convert Hash into String

Of course, then you toss some yummy Hpricot into the mix for parsing/scraping the good bits of the HTML.

About this article

written on
posted in ProgrammingRuby Back to Top

About the Author

Andrew Turner is an advocate of open standards and open data. He is actively involved in many organizations developing and supporting open standards, including OpenStreetMap, Open Geospatial Consortium, Open Web Foundation, OSGeo, and the World Wide Web Consortium. He co-founded CrisisCommons, a community of volunteers that, in coordination with government agencies and disaster response groups, build technology tools to help people in need during and after a crisis such as an earthquake, tsunami, tornado, hurricane, flood, or wildfire.