Python Forum
Getting a GET request output text into a variable to work with it.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a GET request output text into a variable to work with it.
#3
(Feb-24-2021, 01:58 PM)snippsat Wrote: Usually get json back as you data look like.
So like this,some style change and f-string advise to.
import requests

inverter_local_ip = '192.168.XXX.XXX'
inverter_data = requests.get(f'http://{inverter_local_ip}/solar_api/v1/GetPowerFlowRealtimeData.fcgi')
json_data = inverter_data.json()
If this work then data will now be a Python dictionary.
>>> json_data['Body']['Data']['Site']['P_Grid']
650.5
>>> json_data['Body']['Data']['Site']['P_Load']
-4331.5

Thanks a lot! You saved my day!!! Smile Smile Smile

Like that I can work with it perfectly!

import requests

inverter_local_ip = '192.168.178.174' #Local IP of your Fronius Inverter

inverter_data = requests.get('http://%s/solar_api/v1/GetPowerFlowRealtimeData.fcgi' % inverter_local_ip) #Retrieving data from your Inverter
json_data = inverter_data.json()
#print(inverter_data.text) #Displaying the retrieved data

print(json_data['Body']['Data']['Site']['P_Grid'])
print(json_data['Body']['Data']['Site']['P_Load'])
print(json_data['Body']['Data']['Site']['P_PV'])
Reply


Messages In This Thread
RE: Getting a GET request output text into a variable to work with it. - by LeoT - Feb-24-2021, 02:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to output one value per request of the CSV and print it in another func? Student44 3 1,323 Nov-11-2022, 10:45 PM
Last Post: snippsat
  How to combine two output in one variable? ilknurg 2 1,184 Aug-01-2022, 09:31 AM
Last Post: Gribouillis
  Os command output in variable shows wrong value paulo79 2 1,503 Apr-09-2022, 03:48 PM
Last Post: ndc85430
  Search text in PDF and output its page number. atomxkai 21 8,895 Jan-21-2022, 06:20 AM
Last Post: snippsat
  how can I correct the Bad Request error on my curl request tomtom 8 5,058 Oct-03-2021, 06:32 AM
Last Post: tomtom
  Command output to Variable ironclaw 1 1,775 Aug-26-2021, 06:55 PM
Last Post: bowlofred
  Increment text files output and limit contains Kaminsky 1 3,188 Jan-30-2021, 06:58 PM
Last Post: bowlofred
  Variable scope - "global x" didn't work... ptrivino 5 3,033 Dec-28-2020, 04:52 PM
Last Post: ptrivino
  How to Split Output Audio on Text to Speech Code Base12 2 6,856 Aug-29-2020, 03:23 AM
Last Post: Base12
  ImportError: cannot import name 'Request' from 'request' abhishek81py 1 3,922 Jun-18-2020, 08:07 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020