[英]How to get data (items) from eBay Finding API through Google App Engine?
I was trying to retrieve data from eBay Finding API through Google App Engine for a project.我试图通过 Google App Engine 为一个项目从 eBay 查找 API 中检索数据。 It seems to have to do with Google App Engine blocking regular requests.这似乎与 Google App Engine 阻止常规请求有关。
I tried using urlfetch
and urllib3
but to no avail.我尝试使用urlfetch
和urllib3
但无济于事。 I am trying to retrieve item data in JSON format.我正在尝试以 JSON 格式检索项目数据。
This was my first attempt:这是我的第一次尝试:
def get(self):
requests_toolbelt.adapters.appengine.monkeypatch()
http = urllib3.PoolManager()
key = 'WailSahb-Analysis-PRD-4c970d9ce-c9a80d1e'
search_term = 'laptop'
url = ('http://svcs.ebay.com/services/search/FindingService/v1\
?OPERATION-NAME=findItemsByKeywords\
&sortOrder=PricePlusShippingLowest\
&buyerPostalCode=92128&SERVICE-VERSION=1.13.0\
&SECURITY-APPNAME=' + key +
'&RESPONSE-DATA-FORMAT=JSON\
&REST-PAYLOAD\
&itemFilter(0).name=Condition\
&itemFilter(0).value=New\
&itemFilter(1).paramName=Currency\
&itemFilter(1).paramValue=EUR\
&itemFilter(2).paramName=FeedbackScoreMin\
&itemFilter(2).paramValue=10\
&paginationIntput.entriesPerPage=100\
&outputSelector(0)=SellerInfo\
&descriptionSearch=FALSE\
&paginationIntput.pageNumber=1\
&keywords=' + search_term)
url = url.replace(" ", "%20")
result = http.request('GET', url)
self.response.write(result)
With this approach I get the following error:使用这种方法,我收到以下错误:
MaxRetryError: HTTPSConnectionPool(host='pages.ebay.com', port=443): Max retries exceeded with url: /messages/page_not_found.html?eBayErrorEventName=p4buoajkbnmbehq%60%3C%3Dosu71%2872%3A4505-2018.08.16.15.28.47.151.MST (Caused by ProtocolError('Connection aborted.', error(13, 'Permission denied'))) MaxRetryError: HTTPSConnectionPool(host='pages.ebay.com', port=443): 最大重试次数超过 url: /messages/page_not_found.html?eBayErrorEventName=p4buoajkbnmbehq%60%3C%3Dosu71%2872%3A4505-2016.158.08 28.47.151.MST(由协议错误引起('连接中止。',错误(13,'权限被拒绝')))
I also tried this approach:我也尝试过这种方法:
def get(self):
try:
api = Connection(appid='WailSahb-Analysis-PRD-4c970d9ce-c9a80d1e', config_file=None)
response = api.execute('findItemsAdvanced', {'keywords': 'legos'})
assert(response.reply.ack == 'Success')
assert(type(response.reply.timestamp) == datetime.datetime)
assert(type(response.reply.searchResult.item) == list)
item = response.reply.searchResult.item[0]
assert(type(item.listingInfo.endTime) == datetime.datetime)
assert(type(response.dict()) == dict)
self.response.headers['Content-Type'] = 'text/plain'
self.response.write(result.data)
except ConnectionError as e:
self.response.write(e.response.dict())
In which I get this error:我收到此错误:
TypeError: super(type, obj): obj must be an instance or subtype of type TypeError: super(type, obj): obj must be an instance or subtype of type
Could anyone please help me get through this.任何人都可以帮我解决这个问题。
Thank you for your time.感谢您的时间。
I tried to reproduce your problem and had to change a few things, but was eventually able to successfully get the page you're trying to request.我试图重现您的问题并不得不更改一些内容,但最终能够成功获取您尝试请求的页面。
I first copied your first attempt verbatim, and the error I got was slightly different:我首先逐字复制了你的第一次尝试,我得到的错误略有不同:
MaxRetryError: HTTPSConnectionPool(host='pages.ebay.com', port=443): Max retries exceeded with url: /messages/page_not_found.html?eBayErrorEventName=p4buoajkbnmbehq%60%3C%3Dsm%7E71%287147606-2018.08.23.14.59.22.829.MST (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",))
This indicated to me that the that the issue was a missing or invalid SSL module.这向我表明问题是缺少或无效的 SSL 模块。 You didn't share your app.yaml
, but I had to add the following to mine to get the HTTPS request to succeed:您没有分享您的app.yaml
,但我必须添加以下内容才能使 HTTPS 请求成功:
libraries:
- name: ssl
version: latest
However, the eventual app engine response was incorrect, because result
was a urllib3.response.HTTPResponse
object, and not an actual response.然而,最终的应用引擎响应是不正确的,因为result
是一个urllib3.response.HTTPResponse
对象,而不是一个实际的响应。
To fix this, I changed the line:为了解决这个问题,我改变了这一行:
self.response.write(result)
to到
self.response.write(result.content)
and then this worked as intended.然后这按预期工作。
Here's the final versions of the files that made this work for me:以下是对我有用的文件的最终版本:
In app.yaml
:在app.yaml
:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: main.app
libraries:
- name: ssl
version: latest
In main.py
:在main.py
:
import webapp2
from requests_toolbelt.adapters import appengine
import urllib3
class MainPage(webapp2.RequestHandler):
def get(self):
appengine.monkeypatch()
http = urllib3.PoolManager()
key = 'WailSahb-Analysis-PRD-4c970d9ce-c9a80d1e'
search_term = 'laptop'
url = (
'http://svcs.ebay.com/services/search/FindingService/v1\
?OPERATION-NAME=findItemsByKeywords\
&sortOrder=PricePlusShippingLowest\
&buyerPostalCode=92128&SERVICE-VERSION=1.13.0\
&SECURITY-APPNAME=' + key +
'&RESPONSE-DATA-FORMAT=JSON\
&REST-PAYLOAD\
&itemFilter(0).name=Condition\
&itemFilter(0).value=New\
&itemFilter(1).paramName=Currency\
&itemFilter(1).paramValue=EUR\
&itemFilter(2).paramName=FeedbackScoreMin\
&itemFilter(2).paramValue=10\
&paginationIntput.entriesPerPage=100\
&outputSelector(0)=SellerInfo\
&descriptionSearch=FALSE\
&paginationIntput.pageNumber=1\
&keywords=' + search_term)
url = url.replace(" ", "%20")
result = http.request('GET', url)
self.response.write(result.data)
app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.