def test_fetch_url_valid(self): '''Requires remote host to be accessible and responsive.''' txid = ('15796981d90b9ecbce09a9e8a7b4f447566f2f859b808f4e940fb3b6ac17d3' 'd5') url = http.build_tx_url(txid) response = http.fetch_url(url) json_obj = json.loads(response) self.assertEqual(json_obj['ver'], 1)
def test_fetch_url_valid(self): '''Requires remote host to be accessible and responsive.''' txid = ( '15796981d90b9ecbce09a9e8a7b4f447566f2f859b808f4e940fb3b6ac17d3' 'd5') url = http.build_tx_url(txid) response = http.fetch_url(url) json_obj = json.loads(response) self.assertEqual(json_obj['ver'], 1)
def test_create_wallet(api_code): url = ("https://blockchain.info/block-height/0?format=json&api_code=%s" % api_code) resp = http.fetch_url(url) dprint("Resp = %s" % str(resp)) if resp == "Unknown API Key": return False try: if (json.loads(resp)['blocks'][0]['hash'] == '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'): return True else: print_error_and_exit() except Exception: print_error_and_exit()
def test_receive_payments2(api_code): url = (("https://api.blockchain.info/v2/receive?key=%s&xpub=xpub6CDMbK5HbM" "5HjqaQq7a8u9icSSS4b8PewjcKtmUakGFQfft6TT9Xow8MScj1F13YWTjLFESkVbs" "qvFukKf8msyGLkEAE14ji8o554NPHmca&" "callback=http%%3A%%2F%%2Fgoogle.com") % api_code) resp = http.fetch_url(url) json_obj = None try: json_obj = json.loads(resp) except ValueError: print_error_and_exit() if 'message' in json_obj and json_obj['message'] == 'API Key is not valid': return False if 'address' in json_obj: return True else: print_error_and_exit()
def compare_package_to_github(local_data_json, github_location, package_version, extensions_hashed, args): """Downloads the npm package from GitHub and warns about discrepancies. Args: local_data_json (dict): The JSON generated by the current invocation of this script for the target directory. This should be at the JSON level of the npm package being targeted by this function call. The JSON contains previous hashes to compare the GitHub download to. github_location (str): The URL for the project on GitHub, as returned by `npm.get_github_location`. package_version (str): The version of the package being targeted. extensions_hashed (List[str]): A list of filename suffixes that should be SHA-256 hashed. If this list is empty, no files will be hashed. args (List): List of arguments acquired by `parse_args`. """ dprint("Entered compare_package_to_github()") #TODO: need to add a list of items to ignore as differences between local #installed copy and GitHub copy. For example, in package.json file, #_args, _from, etc. assert isinstance(github_location, str) assert isinstance(package_version, str) urls = http.get_possible_zip_urls(github_location, package_version) zip_filename = None for url in urls: if args.verbose: print "Trying to download zip file from '%s'..." % url try: zip_filename = http.fetch_url(url, fetch_tmp_file=True) if args.verbose: print "Successfully downloaded data from '%s'." % url break #found a good url except HTTPError, err: if hasattr(err, 'code') and err.code == 404: continue #try next url else: raise
def fetch_url(self, url): return http.fetch_url(url)
def throttled_fetch_url(self, url): if self.config.API_NUM_SEC_SLEEP > 0: sleep(float(self.config.API_NUM_SEC_SLEEP)) return http.fetch_url(url)