Writing and reading from disk

What I’m trying to do: I had a code that was working very well. which is this one:

audio = row[‘audio’]
audio_bytes = audio.get_bytes()
filename = f’temp_audio_{user[“email”]}’
print(filename)
#write the file to disk
with open(filename, ‘wb+’) as f:
f.write(audio_bytes)
# convert audio to mp3 format
song = AudioSegment.from_file(filename)
mp3_filename = ‘new_audio.mp3’
song.export(mp3_filename, format=“mp3”)

  #read the file before sending it to open ai
  audio_file = open(mp3_filename, "rb")

which was necessary for converting the file to mp3. now is giving me this error:

OSError: [Errno 30] Read-only file system: ‘temp_audio’

did something changed?


**Clone link:**
*share a copy of your app*

I replied just now to a similar post. I think it is relevant in this case, too.

Are you sure the code that worked is the same as what you’ve just pasted? As far as I remember, you’ve never been able to just write to a file in Anvil. There is some ephemeral disk splace you can use in /tmp so maybe your filename was different before?

Here’s the link :

yes I was able to do it, I had this code saved for a long time, and I was able to save temporarily. I think they recently changed this or something.

I tried /tmp like this:

filename = f’/tmp/temp_audio_{user[“email”]}’

and and it gave me the same error…

I’m not able to test it on my system at the moment, but if something has changed you might do better to create a BytesIO object instead of saving to disk (see my link above), or consider doing it over an Uplink.

Thanks a lot for your help. I tried the BytesIO but openai does not work with data bytes. I need to send the audio to openAI for transcription. Any other suggestion?

Ok, I can still write to the /tmp file ok. Here is a clone link to a very simple test :

I think something else might be wrong here. Can you hard code the filename for testing purposes, eg :

with open('/tmp/testingfile', ‘wb+’) as f:

just to see what happens?

EDIT - also, what Anvil plan are you on?

EDIT 2 - also also, print that file name variable, make sure it’s what you expect it to me (ie there’s nothing funny in it)

Im in the professional plan. I think is that over the weekend I had upgrade my build to machine learning for some libraries. Maybe in this build is only read-only.

will try this: with open(‘/tmp/testingfile’, ‘wb+’) as f:

Thanks

update: OSError: [Errno 30] Read-only file system:…

Are you running a local Anvil server rather than using the Anvil hosted one?

I am running a the hosted one which is the default one right?

When I say i upgraded my build i am talking about the servers build options of anvil, “standard” “machine learning” and so on. I think the machine learning is read-only.

EDIT: I am pretty positive is that, i went back to my old build “standard” and the same code now works…

Can we get help from the devs to make machine learning build read and write temporary files?

EDIT II: apparently has something to do with the certifi library, there is a vulnerability found, which ask you to install the last version of certifi. Once you install this, for some reason that I cant still understand you cant write any file into the temporary folder… this happens even in Standard mode…

EDIT III: Finally!, it seems that one of the updates for builds that I was using in my last version of the app improves security of the server (I guess) and was not letting me save the file like this: ‘file’, only like this: ‘’/tmp/file" which was not happening before the update. This was suggested by david.wytie but I am not sure why i did not worked before, I uninstalled all the packages and installed them again and tried with ‘/tmp/’ and it worked. Thanks.

1 Like

Ah ok, I can’t help any further as I have no experience with any of that , sorry.