Neo. The Only. The One.
THE ONE
Any docker experts on here?
Docker kicked my butt this week.
Any docker experts on here?
What problems did you have?Docker kicked my butt this week.
What problems did you have?
The average employee anywhere is not particularly good at what they do. Doesn't matter the industry. If you're even moderately competent then you're already a step ahead. shyt, these people are still struggling to figure out how to screen share half the time. So yes, you're better than you thought you were, and as long as you have even the slightest ability to troubleshoot or seek answers to questions on your own, you'll be head and shoulders above 90% of your peers.so its me and this other dude working together and when I first met him, I thought he was a much better programmer than me cause he was doing it longer and already knew about the backend and all of that.
But over the last couple days, he's been coming to me asking for help for things that he can't figure out.
What does it mean? am I better than I thought I was?
User: {'email': 'sonnyb@company.com', 'name': 'Sonny Bonds', 'id': 323, 'is_archived': Null}
import requests
import json
url = "https://subdomain.clients.us-1.kandji.io/api/v1/devices"
payload={}
headers = {
'Authorization': 'Bearer APIKEYGOESHERE'
}
response = requests.request("GET", url, headers=headers, data=payload)
data = response.json()
for device in data:
print("------------------------------------------------------------")
print(f"Device: {device['device_name']}")
print(f"Model: {device['model']}")
print(f"Serial Number: {device['serial_number']}")
print(f"Platform: {device['platform']}")
print(f"OS Version: {device['os_version']}")
print(f"Last Check In: {device['last_check_in']}")
print(f"User: {device['user']}")
print(f"Blueprint: {device['blueprint_name']}")
print(f"Last Check In: {device['last_check_in']}")
print("------------------------------------------------------------")
Should be able to just do device['user']['name'].In my code, the print(f"User: {device['user']}") line gives me:
How do I print out just the name value? I feel stupid and I feel like I always run into this issue with APIs.
That's what I thought, but when I tried it, I got:Should be able to just do device['user']['name'].
Ah I see. device['user'] is a string and not a JSON object. I don't remember the python library but maybe doing a user = json.loads (device['user']). That should turn that string into a dict, basically, then you should be able to access the individual fields.That's what I thought, but when I tried it, I got:
TypeError: string indices must be integers, not 'str'
My manager sometimes asks me to look over his code or do a mini code review with him. I don't think much of these things. But if it helps you be more confident in your coding ability, then hopefully thats the take away. Just stay humble with it, cause as soon as you think your the goat, a situation pops up to make you feel stupid...or least for me, lolso its me and this other dude working together and when I first met him, I thought he was a much better programmer than me cause he was doing it longer and already knew about the backend and all of that.
But over the last couple days, he's been coming to me asking for help for things that he can't figure out.
What does it mean? am I better than I thought I was?
Yup, good call:Ah I see. device['user'] is a string and not a JSON object. I don't remember the python library but maybe doing a user = json.loads (device['user']). That should turn that string into a dict, basically, then you should be able to access the individual fields.
Thanks.Ah I see. device['user'] is a string and not a JSON object. I don't remember the python library but maybe doing a user = json.loads (device['user']). That should turn that string into a dict, basically, then you should be able to access the individual fields.
My manager sometimes asks me to look over his code or do a mini code review with him. I don't think much of these things. But if it helps you be more confident in your coding ability, then hopefully thats the take away. Just stay humble with it, cause as soon as you think your the goat, a situation pops up to make you feel stupid...or least for me, lol
Ah I see. device['user'] is a string and not a JSON object. I don't remember the python library but maybe doing a user = json.loads (device['user']). That should turn that string into a dict, basically, then you should be able to access the individual fields.
Yup, good call:
Read, Write and Parse JSON using Python - GeeksforGeeks
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.www.geeksforgeeks.org
if (type(user)) == dict:
print(user['name'])
else:
continue