collectiveidea / graticule

Graticule is a geocoding API for looking up address coordinates and performing distance calculations, supporting many popular APIs.
http://rdoc.info/github/collectiveidea/graticule
Other
300 stars 53 forks source link

Needs further error checking from Google Response #34

Closed TravisSpangle closed 7 years ago

TravisSpangle commented 11 years ago

When sending a request to Google it passes back a 200 response of an HTML error message. Graticule assumes the OK status and continues on.

When it gets to Happy Mapper it fails all of the tests for XML locations but still assumes it is XML and falls back to

node = XML::Parser.string(xml).parse.root

This raises an exception and fails the entire process.

[2] (pry) Graticule::Geocoder::Google::Response: 0> exit
Fatal error: AttValue: " or ' expected at :1.
Fatal error: attributes construct error at :1.
Fatal error: Couldn't find end of Start Tag font line 1 at :1.
Fatal error: Opening and ending tag mismatch: b line 1 and font at :1.
Fatal error: AttValue: " or ' expected at :1.
Fatal error: attributes construct error at :1.
Fatal error: Couldn't find end of Start Tag font line 1 at :1.
Fatal error: Opening and ending tag mismatch: td line 1 and font at :1.
Fatal error: AttValue: " or ' expected at :1.
Fatal error: attributes construct error at :1.
Fatal error: Couldn't find end of Start Tag font line 1 at :1.
Fatal error: Opening and ending tag mismatch: tr line 1 and font at :1.
Fatal error: AttValue: " or ' expected at :1.
Fatal error: attributes construct error at :1.
Fatal error: Couldn't find end of Start Tag font line 1 at :1.
Fatal error: Opening and ending tag mismatch: table line 1 and font at :1.
Fatal error: AttValue: " or ' expected at :1.
Fatal error: attributes construct error at :1.
Fatal error: Couldn't find end of Start Tag font line 1 at :1.
Fatal error: Opening and ending tag mismatch: div line 1 and font at :1.
Fatal error: AttValue: " or ' expected at :1.
Fatal error: attributes construct error at :1.
Fatal error: Couldn't find end of Start Tag font line 1 at :1.
Fatal error: Opening and ending tag mismatch: body line 1 and font at :1.
Fatal error: Opening and ending tag mismatch: html line 1 and b at :1.
Fatal error: Extra content at the end of the document at :1.
LibXML::XML::Error: Fatal error: Extra content at the end of the document at /Users/travis/.rvm/gems/ruby-1.9.2-p320@website.com/gems/happymapper-0.4.0/lib/happymapper.rb:95.
from /Users/travis/.rvm/gems/ruby-1.9.2-p320@website.com/gems/happymapper-0.4.0/lib/happymapper.rb:95:in `parse'

HTML Response from google

<html>
   <head>
      <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
      <title>Sorry...</title>
      <style> body { font-family: verdana, arial, sans-serif; background-color: #fff; color: #000; }</style>
   </head>
   <body>
      <div>
         <table>
            <tr>
               <td>
                 <b>
                   <font face=times color=#0039b6 size=10>G</font>
                   <font face=times color=#c41200 size=10>o</font>
                   <font face=times color=#f3c518 size=10>o</font>
                   <font face=times color=#0039b6 size=10>g</font>
                   <font face=times color=#30a72f size=10>l</font>
                   <font face=times color=#c41200 size=10>e</font>
                 </b>
               </td>
               <td style="text-align: left; vertical-align: bottom; padding-bottom: 15px; width: 50%">
                  <div style="border-bottom: 1px solid #dfdfdf;">Sorry...</div>
               </td>
            </tr>
         </table>
      </div>
      <div style="margin-left: 4em;">
         <h1>We're sorry...</h1>
         <p>... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now.</p>
      </div>
      <div style="margin-left: 4em;">See <a href="https://support.google.com/websearch/answer/86640">Google Help</a> for more information.<br/><br/></div>
      <div style="text-align: center; border-top: 1px solid #dfdfdf;">&copy; 2013 Google - <a href="https://www.google.com">Google Home</a></div>
   </body>
</html>
jasonroelofs commented 11 years ago

Yeah, we're not really sure what to do here. Google has become much stricter about the usage of their geocoding API and more people (including ourselves) are getting shut down, which is why we recently updated Graticule's MapQuest handler and moved our project there. While yes error handling could be better handled, there's no way for us to handle this error. You'll need to either pay for Google's API access or switch to another service entirely.

sstarr commented 11 years ago

I had the same problem on a client site which was running an old version (2.0.1) of the gem. Upgrading to the latest version (2.4.0) which uses v3 of the Google API fixed it :+1:

asheren commented 7 years ago

Hi there! We’re doing some open source maintenance work and closing old issues. If you would still like this issue to be addressed, please re-open it by May 17, 2017. Thanks!