Fix module import problems

StringIO and urlopen were changed to different modules. This fixes those issues.
master
kevinhippert 5 years ago committed by GitHub
parent a7c3f63f45
commit 1da0588351
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      flowroutenumbersandmessaging/controllers/cdrs_controller.py

@ -8,8 +8,10 @@
from csv import DictReader from csv import DictReader
import gzip import gzip
import json import json
import StringIO #import StringIO
import urllib2 from io import StringIO
#import urllib2
from urllib.request import urlopen
from .base_controller import BaseController from .base_controller import BaseController
from ..api_helper import APIHelper from ..api_helper import APIHelper
@ -190,7 +192,7 @@ class CDRsController(BaseController):
export_url = _response['data']['attributes']['download_url'] export_url = _response['data']['attributes']['download_url']
#urllib.urlretrieve(export_url, filename) #urllib.urlretrieve(export_url, filename)
try: try:
response = urllib2.urlopen(export_url) response = urlopen(export_url)
compressedFile = StringIO.StringIO(response.read()) compressedFile = StringIO.StringIO(response.read())
decompressedFile = gzip.GzipFile(fileobj=compressedFile) decompressedFile = gzip.GzipFile(fileobj=compressedFile)
with open(filename, 'w') as outfile: with open(filename, 'w') as outfile:
@ -221,4 +223,4 @@ class CDRsController(BaseController):
fileinfo = DictReader(infile) fileinfo = DictReader(infile)
return list(fileinfo) return list(fileinfo)
except Exception as e: except Exception as e:
raise Exception("Error parsing CDR Export data {}".format(e)) raise Exception("Error parsing CDR Export data {}".format(e))

Loading…
Cancel
Save