Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
grayfox35936y@icycrash haven't take a deep look but that for loop looks like trouble.
for json_dict in json_dict:
Assign a different name to the element of json_dict. -
Kimmax109876yfor json_dict in json_dict:
I dont belive that this is going to work. Use better variable names and don't recycle them like that -
This bug should be fixable in waaaaaaay less time than 2 days. 1 look at it and it's clear:
1. Your dict is not a dictionary. The error says so. Errors are rarely wrong.
2. Did you forget to call something? What do you assign to it? A simple look through the code makes it obvious. But a proper editor can also help a lot. Nano is the worst editor for error checking. -
A for loop with the iterable variable and the object your looping shouldn't have the same name. I've never done it but I'd assume that in memory you just overwrote the actual 'json_dict' object and changed it into the first item inside it. Then the next iteration it changes it again.
So instead of a conveyor belt of products. The same product is being taken off the belt then put right back on
EDIT: ohh just saw your new comment. -
I think the issue is the first block. You open a file as json_dict then you reassigned the variable again..maybe that could be it?
-
Kimmax109876y@Kimmax I tried it, while it's not fancy it should work l. However, looping over json_dict probably presents you a key first, instead loop over json_dict["maybe service_plans?"]
That's the reason why you should use an ide, at least as long as you're learning. Or copy it over into a ide to test it instead of 2 days guess work. Hell, even print(json_dict) should be enough. If it's a string you know what's up -
Kimmax109876y@YourNemesis and that's the correct interpretation of the error message. It's not saying "use integers as key", but "you have to use integers as 'key' (indices) when operating ON STRINGS"
-
@Kimmax ohh yea! I think you're right! Looping a dict does just give the key.
To get the values you could do
for i in list(dict):
print dict[i] -
@icycrash
1. remove comments.
2. rename all variables to use something other then json_dict. It is a dumb name, so stop using it.
3. do not open database connection inside for loop. use with pattern when opening it.
4. use filter, or reduce to get the keys/values you need from your file, and iterate over them using enumerate or any other pattern.
the error you are seeing means that what you think is a dict/list is actually a string. -
puzzle1986yjson_dict is a string. It says clearely in the error...
So if you have
myString="abc"
print myString["0"]
that will cause such error. You should access with myString[0] -
puzzle1986yAnd for gods sake you aint using transistor so you have to reuse variable names. Feel free to name variables in a propper way
-
icycrash6836yThanks for all your help. I figured out my problem. Yes I have a database connection opened in a loop. The whole point of this script you have seen peices of pulls information out of ubiquiti's ucrm software using there API then takes key parts of it to inject into free radius SQL database to authenticate radios and que speeds for all 2500 clients.
-
@icycrash dude. please don't tell me this is used on a production system with 2.5k clients...
-
icycrash6836y@magicMirror it is used to for the first sync so we don't have to insert the information twice. It's tested and worked with no errors
-
icycrash6836y@magicMirror and honestly my boss wouldn't give two shits if it was a all the time thing. The cheap asshole is wanting this done to save money because the software is free.
Working with python been banging my head for 2 days and keep getting this error. Tried fixed on Google but not one has worked.
question