def test_async_get(self): async_client_global = AsyncClient(success_callback=self.success_callback, fail_callback=self.fail_callback) params = self.random_dict(10) url = build_url("get") self.assertEquals(async_client_global.get(url, params=params), async_client_global) self.assertEquals(len(async_client_global._data_queue), 1) # Test process_func def process_func(num_processed, remaining, num_urls, success_len, error_len): print("\nProcess {0} {1} {2} {3} {4}".format(num_processed, remaining, num_urls, success_len, error_len)) self.assertEquals(num_urls, 2) def fail_callback(request, errno, errmsg, async_client, opener): self.assertTrue(isinstance(request, Request)) self.assertTrue(isinstance(async_client, AsyncClient)) self.assertEquals(async_client, async_client_global) self.assertEquals(errno, 6) self.assertEquals(errmsg, "Couldn't resolve host '{0}'".format(request.url[7:])) async_client_global.get("http://fwbefrubfbrfybghbfb4gbyvrv.com", params=params, fail_callback=fail_callback) self.assertEquals(len(async_client_global._data_queue), 2) async_client_global.start(process_func)
def success_callback(response, **kwargs): """This function call when response successed """ print("success callback") print(response, response.request) print(response.headers) print(response.content) print(kwargs) def fail_callback(request, opener, **kwargs): """Collect errors """ print("fail callback") print(request, opener) print(kwargs) # In kwargs we can pass default arguments # Add pre and post callback call hooks async_client = AsyncClient(success_callback=success_callback, fail_callback=fail_callback) results = [] fails = [] async_client.get('http://h.wrttn.me/get') async_client.get('http://httpbin.org/get', success_callback=success_callback, fail_callback=fail_callback) async_client.start()
client.method( **{ 'method': 'post', 'url': 'https://sellercentral.amazon.com/fba/profitabilitycalculator/getafnfee', 'data': '{"productInfoMapping":{"asin":"B06W9KM4WG","dimensionUnit": "inches","encryptedMarketplaceId": "","subCategory": "","weight": 1.25,"title": "BEXEL Super Alkaline AA Batteries 24 PACK","weightUnit": "pounds", "isWhiteGloveRequired": false,"imageUrl": "https://images-na.ssl-images-amazon.com/images/I/21qMWE048eL._SCLZZZZZZZ__SL120_.jpg","binding": "consumer_electronics","productGroup": "","height": 3.4646,"thumbStringUrl": "https://images-na.ssl-images-amazon.com/images/I/21qMWE048eL._SCLZZZZZZZ__SL80_.jpg","width": 2.3622,"length": 1.9685,"originalUrl": "", "link": "http://www.amazon.com/gp/product/B06W9KM4WG/ref=silver_xx_cont_revecalc", "dimensionUnitString": "inches", "gl": "gl_electronics", "isAsinLimits": true, "weightUnitString": "pounds"},"afnPriceStr":7.25,"mfnPriceStr":0,"mfnShippingPriceStr":0,"currency":"USD","marketPlaceId":"ATVPDKIKX0DER","hasFutureFee":false,"futureFeeDate":"2018-02-25 00:00:00","hasTaxPage":true} ', 'headers': { 'Content-Type': 'application/json;charset=UTF-8', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36' } }) client.start() # import json # # html = human_curl.post('https://sellercentral.amazon.com/fba/profitabilitycalculator/getafnfee?profitcalcToken=CdKo3CQuKab1GdSryuP6CZYj2F0Jgj3D',data=json.dumps( # {"productInfoMapping": {"asin": "B06W9KM4WG", "dimensionUnit": "inches", # "encryptedMarketplaceId": "", "subCategory": "", "weight": 1.25, # "title": "BEXEL Super Alkaline AA Batteries 24 PACK", # "weightUnit": "pounds", "isWhiteGloveRequired": False, # "imageUrl": "https://images-na.ssl-images-amazon.com/images/I/21qMWE048eL._SCLZZZZZZZ__SL120_.jpg", # "binding": "consumer_electronics", "productGroup": "", # "height": 3.4646, # "thumbStringUrl": "https://images-na.ssl-images-amazon.com/images/I/21qMWE048eL._SCLZZZZZZZ__SL80_.jpg", # "width": 2.3622, "length": 1.9685, "originalUrl": "", # "link": "http://www.amazon.com/gp/product/B06W9KM4WG/ref=silver_xx_cont_revecalc", # "dimensionUnitString": "inches", "gl": "gl_electronics", # "isAsinLimits": True, "weightUnitString": "pounds"},
""" print("success callback") print(response, response.request) print(response.headers) print(response.content) print(kwargs) def fail_callback(request, opener, **kwargs): """Collect errors """ print("fail callback") print(request, opener) print(kwargs) # In kwargs we can pass default arguments # Add pre and post callback call hooks async_client = AsyncClient(success_callback=success_callback, fail_callback=fail_callback) results = [] fails = [] async_client.get('http://h.wrttn.me/get') async_client.get('http://httpbin.org/get', success_callback=success_callback, fail_callback=fail_callback) async_client.start()