« first day (4116 days earlier)      last day (816 days later) » 

12:23 AM
I'm trying to PUT a file into S3 using a presigned url created in Python.
import boto3
import requests

access_key_id = 'AKIA....'
secret_access_key = 'LfNHsQ....'
bucket = 'images-dev'
filename = 'beautiful.png'

s3_client = boto3.client(
  's3',
  aws_access_key_id=access_key_id,
  aws_secret_access_key=secret_access_key
)
response = s3_client.generate_presigned_url(
  ClientMethod = 'put_object',
  Params = {
    'Bucket': bucket,
    'Key': filename,
  }
)

# put
r = requests.put(response, data=open(filename, 'rb'))
print(r.status_code)
That works just fine. But how can I PUT the file using javascript?
 
Wrong room?
 
I asked in the js room too :'(
 
And?
 
no response. I figured Python devs generally have some exposure to JS, and I can't tell which side of the equation is the culprit
 
I don't get it. You said the python version works. So what "which side" of what "equation"? This is a JS question, yes?
 
12:26 AM
fetch(url, {
method: 'PUT',
body: f,
})

is the JS, where url is just the url string and f is a File object
yes I'm pretty sure the JS is the problem
 
What is "not the JS" here?
 
I don't understand your question
 
You said 1. python version works, 2. JS version doesn't work, 3. "I'm pretty sure the JS is the problem". What else could be the problem when you have JS that doesn't work?
 
I mean there are differences between making a request server side and client side--I'm not sure if I need to add something special to the url on the Python side to allow the JS to send the PUT successfully
 
So the server is in Python. That's the "not the JS" that might be off?
 
12:31 AM
yes either the Python is off or the JS is off or both
 
12:44 AM
curiously, s3 throws a 403 if I add 'ContentType': 'image/png' to the Params
 
 
1 hour later…
1:55 AM
Lord god, if one adds the ContentType attribute and send the PUT request with requests, you get a 403. But to send the PUT with JS one needs to add the ContentType attribute. Then one can:
var xhr = new XMLHttpRequest();
xhr.open('PUT', url);
xhr.onreadystatechange = () => {
  if (xhr.readyState === 4) {
    if (xhr.status !== 200) {
      console.log('Could not upload file.');
    }
  }
};
xhr.send(f);
 
2:21 AM
I got to edit a Flask template file for a test app today - boy, the PyCharm integration for that is pretty nice! (Auto-complete in the html template corresponding to values defined in the .py file - how does it know?)
 
 
14 hours later…
4:28 PM
Okay I fixed my problem here is the solution
Edit Fixed:

import keyboard

def on_alt(event):
if keyboard.is_pressed('ctrl'):
print('Ctrl + Alt pressed')

keyboard.on_press_key('alt', on_alt)
time.sleep(1e6)
@PaulMcG pycharm is very good but it is pretty heavy
 
 
2 hours later…
6:43 PM
Off-topic: some interesting HN discussion on optimal strategy for Wordle, and a prime-number-based copycat 'Primel' news.ycombinator.com/item?id=30023286
 
 
4 hours later…
10:48 PM
Quick question for my sanity: is PyQt5==5.13.0 not compatible with python 3.10.1? I can't find requirements, and pip can't install it
 
I have no idea but I bet it's not compatible, yes
Wait, PyQt5 5.13.0 was released in July 2019
 
yah
spyder ide still requires <= 5.13
 
> Python 3.10.0

Release Date: Oct. 4, 2021
Whatcha think?
@Aaron sounds like a great opportunity to ditch spyder :P
 
I've used spyder for like a decade...
 
my sympathies
 
10:51 PM
I have various installs that I hot-swapped python versions and somehow have it working
imao spyder is actually great usually
I can't stand pycharm
 
variety is the spice of life
 
ffs pip needs better deps resolving :/
 
I mean pip can only ask the package. And there's no way a package released in 2019 would say that it's compatible with a Python version that will have been released mroe than 2 years later. I mean I guess it could, but there will be no wheels. I don't know if pip can build from source, and even if it did then something like PyQt5 could easily not build with an unexpected Python version.
(But I wouldn't know, I'm not a PyQt5 nor spyder user)
 

« first day (4116 days earlier)      last day (816 days later) »