-
Notifications
You must be signed in to change notification settings - Fork 5
URI::InvalidURIError (bad URI(is not URI?)
Reena H Rajani edited this page Jun 2, 2015
·
1 revision
Running my application on Heroku generated the following error
URI::InvalidURIError (bad URI(is not URI?): https://api.edamam.com/search?q=chickpea curry&app_id=c5975da7&app_key=5cc84166d69454f54ed43fb1bcb9b858):
This URL contains special characters, which Ruby can’t handle (my guess)
Encode the url and then parse it encoded_url = URI.encode(url.strip) URI.parse(encoded_url)
- Strip removes the leading and trailing whitespaces
- URI.encode --> used to avoid the special characters
encoded_url = URI.encode(url.strip) => "https://api.edamam.com/search?q=vegemite,bourbon&app_id=c5975da7&app_key=5cc84166d69454f54ed43fb1bcb9b858"
uri = URI.parse(encoded_url) => #<URI::HTTPS https://api.edamam.com/search?q=vegemite,bourbon&app_id=c5975da7&app_key=5cc84166d69454f54ed43fb1bcb9b858>