1

我使用刻度线 1.0.0.pre2。当我尝试查找一些 Google 无法识别的地址时,graticule 会引发异常:

LibXML::XML::Error in Cms/storesController#update

Fatal error: Extra content at the end of the document at :1.
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/happymapper-0.3.2/lib/happymapper.rb:84:in `parse'
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/happymapper-0.3.2/lib/happymapper.rb:84:in `parse'
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/graticule-1.0.0.pre2/lib/graticule/geocoder/google.rb:82:in `prepare_response'
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/graticule-1.0.0.pre2/lib/graticule/geocoder/base.rb:83:in `get'
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/graticule-1.0.0.pre2/lib/graticule/geocoder/google.rb:36:in `locate'
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/acts_as_geocodable-1.0.4/lib/acts_as_geocodable/geocode.rb:31:in `create_from_location'
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/acts_as_geocodable-1.0.4/lib/acts_as_geocodable/geocode.rb:27:in `find_or_create_by_location'
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/acts_as_geocodable-1.0.4/lib/acts_as_geocodable.rb:262:in `attach_geocode'
...
...

我正在使用谷歌服务。这是生成异常的响应:

"<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=\"http://www.google.com/support/bin/answer.py?answer=86640\">Google Help</a> for more information.<br/><br/></div><div style=\"text-align: center; border-top: 1px solid #dfdfdf;\">&copy; 2009 Google - <a href=\"http://www.google.com\">Google Home</a></div></body></html>"

与其他地址一起工作!我怎样才能防止这种异常?

4

1 回答 1

0

我收到了同样的错误。使用 Pry 调试器,我在快乐映射器的 Parse 声明下放置了一个 binding.pry。对你来说,那将是

/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/happymapper-0.3.2/lib/happymapper.rb:84:in `parse'

重新启动并运行

location = geocoder.locate("61 East 9th Street, Holland, MI")

调试器立即停止

def parse(xml, options = {})

我对 xml 变量进行了转储,以从 Google 接收包含该消息的 HTML 转储

<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>
See <a href="https://support.google.com/websearch/answer/86640">
    Google Help
</a> for more information.

还没有解决,但这就是问题所在。

于 2013-10-31T23:12:12.643 回答