|
Yeah, missing qoutes around the key.
|
# ? Mar 30, 2018 21:22 |
|
|
# ? May 16, 2024 18:21 |
|
Yeah, I forgot the quotes, eesh. Thanks for the help!
|
# ? Mar 30, 2018 21:24 |
|
Ok, this time I'm sure it's not me (I hope). I'm using the same code but typo-corrected:code:
So I thought that maybe they gave me the wrong URL, but if I use "requests.post" instead of "requests.put" I get: "requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://photoai.lotlinx.com/images/optimize" So that makes me think that the URL is valid, but there's something in the request that it's not liking. In the documentation, it says: "1. SUBMIT REQUESTS Host - https://photoai.lotlinx.com POST /images/optimize" Is there any reason that they would put it like that? I thought maybe it's necessary to first access the URL with the username and password and then pass the files on to the /images/optimize folder, but nothing in the Requests documentation seems to allow for doing things like that. I tried accessing the URL through a web browser and used the username/password and just got an authentication error instead of a 404, so I think the URL must be valid. I feel like I might be missing something obvious here, any ideas?
|
# ? Mar 31, 2018 02:53 |
It sounds like it's legitimately giving you an authentication error. Are you literally sending "username" and "password" as the username and password like in your code? Didn't the docs describe what to use for those values?
|
|
# ? Mar 31, 2018 03:16 |
|
No, I'm using the u/p that they sent me in an email - so it's possible that the info is incorrect. Wouldn't an invalid username or password bring up a different kind of error, though?
|
# ? Mar 31, 2018 04:02 |
|
Seventh Arrow posted:No, I'm using the u/p that they sent me in an email - so it's possible that the info is incorrect. Wouldn't an invalid username or password bring up a different kind of error, though? Presumably 401, yes.
|
# ? Mar 31, 2018 17:31 |
|
Seventh Arrow posted:Ok, this time I'm sure it's not me (I hope). I'm using the same code but typo-corrected: Try it with a tool like this chrome extension: Advanced REST client. Might give you more information...
|
# ? Mar 31, 2018 17:33 |
|
Thermopyle posted:Try it with a tool like this chrome extension: Advanced REST client. This is strange, because when I use the app, it goes through ok with a '200'. The only differences is that the python code is being run from my linux laptop, whereas the ARC app is being run from my Windows 10 desktop. Also, the laptop is also using python but none of the code seems out of place. This is going to take a bit of thinking.
|
# ? Mar 31, 2018 19:09 |
|
I've wasted a lot of time trying to figure out an efficient way to do this. I have three 2D arrays of which contain each element's latitude, longitude, and an arbitrary value we'll call Z. I wish to find a way to determine the x/y coordinates of where arbitrarily located smaller domains overlap.The smaller domains would also have lat/lon data, and I wish to extract the Z data for the area of overlap and set those values in the smaller arrays. Both the larger and smaller arrays are from the same projection, so lat/lon values will be the same in both. Visually, I am wanting to find where the red squares exist within the blue square's domain, then extract the values in yellow from the blue array and input them into the red arrays. Any ideas?
|
# ? Mar 31, 2018 22:09 |
|
This is basically just going to be an AABB test for each small square. Test which ones intersect, then if they do: Test which vertices intersect, Find the point on the edge that intersects the rectangle's edge between adjacent vertices that do and don't intersect to make a "subrectangle" that fully intersects (if any two adjacent vertices both intersect, they're both part of the subrectangle). *** To be clear, this is just a line segment test between segments that are partially inside the rectangle. You can find the point that segment intersects and it becomes a "new" vertex that's fully inside the rectangle. Iterate over this subrectangle of the test rectangle and copy the Z's That's the easiest way to do it I can think of. You can also, of course, use BVHs or spatial hashing or whatever if you think there will be a significant number of test rectangles that don't intersect at all. E: Also, if you end up with only 3 intersecting vertices, you need to find which you're missing and then sub in the appropriate x,ys from the other points. E2: I made a crummy gif Linear Zoetrope fucked around with this message at 22:48 on Mar 31, 2018 |
# ? Mar 31, 2018 22:19 |
|
Instead of explicitly searching intersections it would probably be easier (at least from a coding perspective) to use pandas and merge dataframes.
|
# ? Mar 31, 2018 22:49 |
|
Dr Subterfuge posted:Instead of explicitly searching intersections it would probably be easier (at least from a coding perspective) to use pandas and merge dataframes. TBH I missed this was the Python thread, saw intersecting rectangles and went "obviously this is the game dev thread, let's go in graphics/geometry mode "
|
# ? Mar 31, 2018 23:17 |
|
Seventh Arrow posted:This is strange, because when I use the app, it goes through ok with a '200'. Maybe they're filtering on user agent?
|
# ? Apr 1, 2018 00:21 |
|
Actually I tried using ARC on the linux laptop and it works there too the only thing that I can think of is maybe I need to use something other than "json=files". In ARC, I didn't specify anything for "Body Content Type." I updated the code a little bit: code:
|
# ? Apr 1, 2018 00:26 |
|
Linear Zoetrope posted:This is basically just going to be an AABB test for each small square. Test which ones intersect, then if they do: Seeing your crummy gif triggered the idea that I need to find where a column intersects a row. It's a little trickier though because the lat/lons are projected, meaning they won't have a simple linear increase/decrease. But this idea... Dr Subterfuge posted:Instead of explicitly searching intersections it would probably be easier (at least from a coding perspective) to use pandas and merge dataframes. I hadn't considered that. I'll give it a try, may be relatively quick and easy!
|
# ? Apr 1, 2018 01:27 |
|
Seventh Arrow posted:Actually I tried using ARC on the linux laptop and it works there too the only thing that I can think of is maybe I need to use something other than "json=files". In ARC, I didn't specify anything for "Body Content Type." At this point, I'd probably start up Charles and compare the request data from python and from ARC.
|
# ? Apr 1, 2018 17:24 |
|
Dr Subterfuge posted:Instead of X it would probably be easier to use pandas
|
# ? Apr 1, 2018 18:06 |
|
Thermopyle posted:At this point, I'd probably start up Charles and compare the request data from python and from ARC. This looks really handy, thank you.
|
# ? Apr 1, 2018 18:44 |
|
Cingulate posted:Thread title I had this feeling I had read some joke about how often pandas was recommended in this thread. Somehow I actually hadn't known about it until I read about it here. Intersections between tabular data sounds like a pretty good use case at least!
|
# ? Apr 1, 2018 19:09 |
|
Is there a good way to pass data between two scripts running on two different environments? I'm working with Civ IV, which enables Python scripting with Python 2, and am grabbing scoring data. Every few turns, I would like to run that scoring data through a script that uses Python 3-specific modules, and then return a single value to the Python 2 script. Right now, the best I can think of is having both scripts read from and write to the same file.
|
# ? Apr 1, 2018 23:07 |
|
It's hokey, but that's what I'd do unless I ran into some sorta concurrency issues.
|
# ? Apr 1, 2018 23:17 |
|
You can also run an http server in the python 3 process and have the python 2 process interact with that to signal when it should do things.
|
# ? Apr 1, 2018 23:56 |
|
So I managed to clear up the previous problem...apparently using "post" instead of "put" and "json=files" instead of "data=files" did the trick The next thing I want to verify is that there's no simple way to access a value in a nested dictionary, correct? When I print "requests.json()" I get this string: {'data': [{'token': 'bYrIXkbPK933im6zpM4GoPB59i7pxLhkfAbdCrQr7kWFrjnH5hW5Z130uqqSI1uU', 'status': 'queued'}], 'status': 200} I need to take the value for 'token' and put it in a URL, like 'https://photoai.lotlinx.com/images/<token>/status' but all the googling I've done seems to indicate that I need a function to pull out the value...does that sound right?
|
# ? Apr 2, 2018 01:55 |
|
I mean you could (and should) make that into a function, but you can get the token by doing requests.json()['data'][0]['token'] directly. To expand, request.json() returns a python dictionary (and not a string), that is, in short, a data structure that maps keys into values. So, for that particular dictionary, your token is inside a dictionary, under the key "token", that is inside a single element list (so index 0), that is inside another dictionary, under the key "data".
|
# ? Apr 2, 2018 02:09 |
|
That's great, thank you. Could you maybe explain why it's necessary to put the [0] between ['data'] and ['token']? (and maybe where I could find more info on the topic?)
|
# ? Apr 2, 2018 02:21 |
|
It's in a list Python has collection types, dict, and list, which are used for json arrays and objects: code:
If you're asking questions like this, you might want to run through, or skim over the python tutorial, just to get a feel for some of the names of things. https://docs.python.org/3/tutorial/ You can pick the right version of the tutorial to match your version of python
|
# ? Apr 2, 2018 02:30 |
|
Pandas you're my hero. I figured there was a simple python way to do this. Thank you for the suggestion!code:
|
# ? Apr 2, 2018 02:32 |
Seventh Arrow posted:That's great, thank you. Could you maybe explain why it's necessary to put the [0] between ['data'] and ['token']? (and maybe where I could find more info on the topic?) Because the [] brackets mean an array or list. There is only one element in that list, the {'token': 'bYrIXkbPK933im6zpM4GoPB59i7pxLhkfAbdCrQr7kWFrjnH5hW5Z130uqqSI1uU', 'status': 'queued'} dict; but you still have to specify which element in the list you want. Formatted out, your dict might look like this, with more than one item in the list: code:
Data Graham fucked around with this message at 02:36 on Apr 2, 2018 |
|
# ? Apr 2, 2018 02:32 |
|
Thanks to everyone's help, I was able to tear through a lot of the rest of the project. I'm stuck on the last bit, though...the API has generated some image files and I need to download them, preferable to a specific directory. Without going too much into how I got here, here is the list of image URLs:code:
code:
So as mentioned, I want to download these files. I want to do it in a way that uses the existing filenames, but I'm not familiar with the process. To generate a list of the files and the intended location, I did this: code:
So finally, this is what I tried for downloading the files into the directory with their original filenames: code:
TypeError Traceback (most recent call last) <ipython-input-188-474e4bda9ae7> in <module>() 1 for img in img_url: 2 response = requests.get(img, stream=True) ----> 3 handle = open(locs, "wb") 4 for chunk in response.iter_content(chunk_size=512): 5 if chunk: TypeError: invalid file: ['/home/seventh_arrow/Documents/project/jeep_wrangler%2520unlimited_2014_1C4BJWFG3EL326863_7416_339187295.png', '/home/seventh_arrow/Documents/project/jeep_wrangler%2520unlimited_2014_1C4BJWFG3EL326863_7416_2_339187295.png', '/home/seventh_arrow/Documents/project/jeep_wrangler%2520unlimited_2014_1C4BJWFG3EL326863_7416_3_339187295.png', '/home/seventh_arrow/Documents/project/jeep_wrangler%2520unlimited_2014_1C4BJWFG3EL326863_7416_4_339187295.png', '/home/seventh_arrow/Documents/project/jeep_wrangler%2520unlimited_2014_1C4BJWFG3EL326863_7416_5_339187295.png'] Admittedly, the last bit of code is ripped off from someone's blog so I'm not 100% what everything does. Is there any way to make it work?
|
# ? Apr 3, 2018 03:50 |
|
You can't open a list of file paths. You have to do it one at a time.
|
# ? Apr 3, 2018 03:55 |
|
Yikes, really? So if it generated a hundred files, I'd be pretty hosed. I guess for now I'll just be thankful that the exercise only has five files. So should I just do five "for img in img_url:" passes, each with a different filename?
|
# ? Apr 3, 2018 03:59 |
|
Seventh Arrow posted:Yikes, really? So if it generated a hundred files, I'd be pretty hosed. Why do you think that?
|
# ? Apr 3, 2018 04:01 |
|
Seventh Arrow posted:Yikes, really? So if it generated a hundred files, I'd be pretty hosed. I guess for now I'll just be thankful that the exercise only has five files. You can iterate over your urls and locations at the same time with zip. Python code:
|
# ? Apr 3, 2018 04:18 |
|
Thermopyle posted:Why do you think that? Maybe I misunderstood him, but it kind of sounds like you have to do everything manually, instead of letting python feed the image names and URLs into the file-generating functions.
|
# ? Apr 3, 2018 04:44 |
|
You don't have to have any more infrastructure than what I posted. In your code there isn't actually any reason to want to open a bunch of files simultaneously anyway, since each url is accessed sequentially, and each url corresponds to one location.
|
# ? Apr 3, 2018 05:12 |
|
If you're writing data (app settings, cache, whatever) to disk at what point do you drop Python/pickle/json in individual files and move to SQLite? To my mind the threshold here is pretty low-- otherwise I'm writing a bunch of file load/save stuff, possibly worrying about contention, race conditions on the file(s) etc. when I could just let the database handle it. Am I wrong? This is a very light duty internal / test project-- say 50 reads and 10 writes per day so it's almost a waste of time to even worry about it. But say I scale up 10-100x from there, what choice would you make? Since SQLite is in the standard Python3 library why would you not use it for this type of case?
|
# ? Apr 3, 2018 06:32 |
|
Is there such thing as "statically compiling" an executable Python script? I would like to be able to just distribute the script as an executable with dependencies baked into it so that I don't need to worry about sourcing or creating a venv and whatnot.
|
# ? Apr 3, 2018 11:29 |
|
Boris Galerkin posted:Is there such thing as "statically compiling" an executable Python script? I would like to be able to just distribute the script as an executable with dependencies baked into it so that I don't need to worry about sourcing or creating a venv and whatnot. Yeah py2exe or pex
|
# ? Apr 3, 2018 11:53 |
|
Is there a simple common method to correct typos ? I have a list of maybe mistyped words, and a csv with the reference spelling. The CSV has 36000 entries. I can bruteforce it using Levenshtein distance between each word of each list but it's massively inefficient. e: I found this unpacked robinhood fucked around with this message at 10:23 on Apr 5, 2018 |
# ? Apr 5, 2018 09:40 |
|
|
# ? May 16, 2024 18:21 |
|
unpacked robinhood posted:Is there a simple common method to correct typos ? I've run Levenshtein and LCS on bigger lists and it took on the order of minutes, not days, so it's not that bad, even if it is technically very inefficient. I'd characterize filling memory with every edit distance of 1 and 2 as brute force adjacent, at least
|
# ? Apr 5, 2018 13:46 |