From beb106a33fdc0555ebc32669b93be0895b16b745 Mon Sep 17 00:00:00 2001 From: Marko Bastovanovic Date: Wed, 14 Feb 2018 15:14:46 +0100 Subject: [PATCH] switch to requests instead of urllib2 due to problem with SSL and python<2.7.9 --- emr_cost_calculator.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/emr_cost_calculator.py b/emr_cost_calculator.py index 9e8c438..f71e05e 100755 --- a/emr_cost_calculator.py +++ b/emr_cost_calculator.py @@ -33,8 +33,7 @@ from retrying import retry import sys import datetime -import urllib2 -import json +import requests def validate_date(date_text): @@ -77,13 +76,13 @@ class Ec2EmrPricing: def __init__(self, region): url_base = 'https://pricing.us-east-1.amazonaws.com' - index_response = urllib2.urlopen(url_base + '/offers/v1.0/aws/index.json') - index = json.loads(index_response.read()) + index_response = requests.get(url_base + '/offers/v1.0/aws/index.json') + index = index_response.json() - emr_regions_response = urllib2.urlopen(url_base + index['offers']['ElasticMapReduce']['currentRegionIndexUrl']) - emr_region_url = url_base + json.loads(emr_regions_response.read())['regions'][region]['currentVersionUrl'] + emr_regions_response = requests.get(url_base + index['offers']['ElasticMapReduce']['currentRegionIndexUrl']) + emr_region_url = url_base + emr_regions_response.json()['regions'][region]['currentVersionUrl'] - emr_pricing = json.loads(urllib2.urlopen(emr_region_url).read()) + emr_pricing = requests.get(emr_region_url).json() sku_to_instance_type = {} for sku in emr_pricing['products']: if emr_pricing['products'][sku]['attributes']['softwareType'] == 'EMR': @@ -95,10 +94,10 @@ def __init__(self, region): price = float(emr_pricing['terms']['OnDemand'][sku].itervalues().next()['priceDimensions'].itervalues().next()['pricePerUnit']['USD']) self.emr_prices[instance_type] = price - ec2_regions_response = urllib2.urlopen(url_base + index['offers']['AmazonEC2']['currentRegionIndexUrl']) - ec2_region_url = url_base + json.loads(ec2_regions_response.read())['regions'][region]['currentVersionUrl'] + ec2_regions_response = requests.get(url_base + index['offers']['AmazonEC2']['currentRegionIndexUrl']) + ec2_region_url = url_base + ec2_regions_response.json()['regions'][region]['currentVersionUrl'] - ec2_pricing = json.loads(urllib2.urlopen(ec2_region_url).read()) + ec2_pricing = requests.get(ec2_region_url).json() ec2_sku_to_instance_type = {} for sku in ec2_pricing['products']: