我使用格线1.0.0.pre2。当我尝试找到Google无法识别的某些地址时,格线会引发异常:
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'
...
...
我正在使用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=\"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;\">© 2009 Google - <a href=\"http://www.google.com\">Google Home</a></div></body></html>"
使用其他地址可行!如何防止该异常?
答案 0 :(得分:0)
我收到同样的错误。使用Pry调试器我在happy mapper中的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'
重新启动pry并运行
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.
尚未解决,但这就是问题所在。