0

I am trying to calculate the Azure usage cost in python by getting response from url API with importing urllib3.

But I am not getting full data in the response. Partial data is coming. My requirement is to get this data day wise and have to send a mail for 5 days with comparison. I am able to get this in powershell, but not in Pyhton.

Here is the code I am using:

import requests
import datetime
import json
import logging
import urllib3
import csv
#logging.raiseExceptions=False
Enrollmentnbr = 'xxxx'
key  = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
month= datetime.date.today().strftime('%Y-%m')
urlbase = 'https://ea.azure.com/rest/'
#authHeaders = {'Authorization': 'Bearer ' + key}
url= urlbase + Enrollmentnbr + "/usage-report?month="+month+"&type=detail"

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36',
      'Authorization': 'Bearer {0}'.format(key)}

http = urllib3.PoolManager()
response = http.request('GET', url=url,headers=headers)
Neuron
  • 5,141
  • 5
  • 38
  • 59
vin123
  • 3
  • 6
  • what exactly do you mean by "partial data is coming"? also, did you try to read the response in chunks? response = http.request('GET', url=url,headers=headers, preload_content=False) for chunk in response.stream(32):print(chunk) response.release_conn() – andresm53 Jul 05 '18 at 15:50
  • I mean to say only some data is coming not at all the information. I didn't tried the response in chunks, i will try this. – vin123 Jul 06 '18 at 05:45

0 Answers0