Hi I'm trying to get information from a whole list of items from my AGOL. To make that happen I made a txt file with all the ID's of the items that I want to approach. And for each item I want to get the information of the item. See code below.
urls= open("dir to file with urls")
for x in urls:
print(x)
item = gis.content.get(x)
print(item)
Using the variable as shown above i get a 400 bad request error in return. However if I directly feed the ID in there like this: item = gis.content.get("458254021f2c47b2bb5ccaebd39323b2") I get the result I want.
Any idea on what could change if im trying to parse them from a variable instead of doing it by hand?
It would help to know what x is - is that part printing okay? It would also help to know how the txt file is written. Line by line? Maybe there's some whitespace?
I imagine you would want to being doing something like this:
with open("/your/file") as f:
lines = [line.strip() for line in f]
for line in lines:
item = gis.content.get(line)
Thank you for your response, x returns the ID of the item im doing the .get() method on.
the txt file is written in line for line, with no extra white between them.
"x" also returns the ID just as they are written in the file, even when i copy the ID from the log into the url directly it returns a normal value.
Im going to try the suggested code and will get back to you. Thank you in advance!
Okay i have done a couple of more tests, for some reason the old code now returns the right values as well. I think after all it might have been a backend thing that i could not place. Thanks for thinking with me regardless.