繁体   English   中英

如何通过 Google App Engine 从 eBay 查找 API 获取数据(项目)?

[英]How to get data (items) from eBay Finding API through Google App Engine?

我试图通过 Google App Engine 为一个项目从 eBay 查找 API 中检索数据。 这似乎与 Google App Engine 阻止常规请求有关。

我尝试使用urlfetchurllib3但无济于事。 我正在尝试以 JSON 格式检索项目数据。

这是我的第一次尝试:

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)

使用这种方法,我收到以下错误:

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,'权限被拒绝')))

我也尝试过这种方法:

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())

我收到此错误:

TypeError: super(type, obj): obj must be an instance or subtype of type

任何人都可以帮我解决这个问题。

感谢您的时间。

我试图重现您的问题并不得不更改一些内容,但最终能够成功获取您尝试请求的页面。

我首先逐字复制了你的第一次尝试,我得到的错误略有不同:

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.",))

这向我表明问题是缺少或无效的 SSL 模块。 您没有分享您的app.yaml ,但我必须添加以下内容才能使 HTTPS 请求成功:

libraries:
- name: ssl
  version: latest

然而,最终的应用引擎响应是不正确的,因为result是一个urllib3.response.HTTPResponse对象,而不是一个实际的响应。

为了解决这个问题,我改变了这一行:

self.response.write(result)

self.response.write(result.content)

然后这按预期工作。


以下是对我有用的文件的最终版本:

app.yaml

runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: main.app

libraries:
- name: ssl
  version: latest

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM