Problems runing a code with ipynb in google drive - python

Sooo, this is more of theoretical question. I have a python code that runs just fine in Pycharm but started to not work anymore in my .ipynb drive file. It downloads and writes over a binary document.
The code fails were trying to open the downloaded file for writing with the error message that '[Errno 2] No such file or directory:'.
I'm not sure if it is involved in the problem, but these lines below used to run without warnings, but now google drive asks for my permission for them to run:
drive.mount('/content/drive') drive.mount('/content/drive', force_remount=True)
As a told before, since the code runs without error in pycharm, I was wondering if you guys know whether this is a "google drive new update" kinda of thing, or a "jupiter notebook problem" or something else maybe?
EDIT: here's the message google drive sends me

Related

Can you self sign a pyinstaller program so that it doesn't show up as a virus when giving it to other poeple?

I am creating a python program and converting it into a .exe with auto-py-to-exe(a gui for pyinstaller). I uploaded it to my google drive for my friend to download but he cant download it since chrome and google drive thinks its a virus. I couldn't even send it through gmail (I had to use AOl...... funny how AOl does that). I know the file isn't signed and thats whats likely making it look like a virus, I didn't know if there was a way to sign the code so that google doesn't throw hissy fits about it.

EZSheets Module won't open Window to log into Google account

I'm learning Python using Automate the Boring Stuff and I am currently on Chapter 14 which centers on using EZSheets to work with Google Sheets.
The book says to place the credentials-sheets.json file in the same folder as the Python scripts, so I placed it in the "\Python38\Scripts" folder.
The next step is to run import ezsheets and it will open a new browser window for me to log in to my Google account. Here is where I am stuck. Importing EZSheets does nothing. I don't get any errors, but it doesn't open the window for me to log into my Google account.
All the code I used was:
import ezsheets
I just spent about the last 2 hours tackling this problem. As someone with a thin layer of SQL and Python experience...I was very frustrated with your same problem. Here's what I did when I got stuck in a couple places.
It might just be that you need to change the directory you are working in to "\Python38\Scripts" and then run the script, like you mentioned. If not, here's what I did next.
I followed the ezsheets doc's, much like you, except I skipped over the Google Python Quickstart guide linked in the doc. No problem, I circled back and found it.
"Setting up the Same" was my next issue. First problem there: the documentation says to name your credentials "credentials-sheets.json" while the Google quickstart.py file calls for "credentials.json". You have to change that in the quickstart.py file (and quickstart.py should be in the same file location as the credentials. In your case: "\Python38\Scripts").
Look for this
flow = InstalledAppFlow.from_client_secrets_file(
'credentials-sheets.json', SCOPES)
The above is what I fixed in the quickstart.py file (to be the same as the ezsheets documentation) and worked for me.
Then, I was getting a 400 error when running Quickstart. The browser window would open and it would give me this Authorization Error: "Error 400: redirect_uri_mismatch". It specified that I did not have the right redirect URL authorized. Stumped me for a while but if you can get to your developer console and edit the credentials, you can add the local host location and the port number given to you in the error.
Here comes the final issue with that solution. In the quickstart, "port:0" was specified and it would randomize every time I added the most recent port number to the authorization. After adding 3-4 ports and having it change on me, I saw in the quickstart.py file that I needed to specify the port like so.
creds = flow.run_local_server(port=8080)
After changing that in the quickstart.py file and adding that to my "Authorized redirect URI's" in Developer Console, I was able to finish this step and move on.
I'm open to criticism if this is incorrect. I found those two errors were missing from every answer I came across. Hopefully this saves some people some time while trying to setup ezsheets to sync with Google Drive and Google Sheets.
For the import command to work you must first type python or python3 to your command prompt while inside the directory you want to import ezsheets Once you have the python prompt then import ezsheets command will work

Running an exe file on the azure

I am working on an azure web app and inside the web app, I use python code to run an exe file. The webapp recieves certain inputs (numbers) from the user and stores those inputs in in a text file. Afterwards, an exe file would run and read the inputs and generate another text file, called "results". The problem is that although the code works fine on my local computer, as soos as I put it on azure, the exe file does not get triggered by the following line of code:
subprocess.call('process.exe',cwd = case_directory.path, shell= True)
I even tried running the exe file on Azure manually from the Visual Studio Team Services (was Visual Studio Online) by "running from Console" option. It just did not do anything. I'd appreciate if anyone can help me.
Have you looked at using a WebJob to host\run your executable from? A WebJob can be virtually any kind of script or win executable. There are a number of ways to trigger your WebJob. You also get a lot of buit in monitoring and logging for free as well, via the Kudu interface.
#F.K I searched some information which may be helpful for you, please see below.
Accroding to the python document for subprocess module, Using shell=True can be a security hazard. Please see the warning under Frequently Used Arguments for details.
There is a comment in the article which gave a direction for the issue, please see the screenshot below.
However, normally, the recommended way to satisfy your needs is using Azure Queue & Blob Storage & Azure WebJobs to save the input file into a storage queue, and handling the files got from queue and save the result files into blob storage by a continuous webjob.

Can't auto-start Python program on Raspberry Pi due to Google Calendar

I have written a python tkinter program which runs on my Raspberry Pi, which does a number of things, including interfacing with my google calendar (read only access). I can navigate to the directory it is in and run it there - it works fine.
I would like the program to start at boot-up, so I added it to the autostart file in /etc/xdg/lxsession/LXDE, as per advice from the web. However it does not start at boot. So I try running the line of code I put in that file manually, and I get this.
(code I run) python /home/blahblah/MyScript.py
WARNING: Please configure OAuth 2.0
To make this sample run you will need to download the client_secrets.json file and save it at:
/home/blahblah/client_secrets.json
The thing is, that file DOES exist. But for some reason the google code doesn't realise this when I run the script from elsewhere.
How then can I get my script to run at bootup?
Figured this out now. It's tough, not knowing whether it's a Python, Linux or Google issue, but it was a Google one. I found that other people across the web have had issues with client_secrets.json as well, and the solution is to find where its location is stored in the Python code, and instead of just having the name of the file, include the path as well, like this.
CLIENT_SECRETS = '/home/blahblahblah/client_secrets.json'
Then it all works fine - calling it from another folder and it starting on startup. :)

Protect Python script with Google Drive (perhaps Google App Engine)

I have trouble with understanding if it's possible to protect a python script from stealing it (I know this is not in fact possible but at least let's protect it as much as possible) by uploading the program made in python to Google Drive. I did reasearch such as How do I protect my python code? or Store Python scripts & run them online? and many more or less relevant links. But none of them is really answering me.
Let's say I have a python project made a Windows Executable (.exe) with GUI2Exe. It has GUI which loads images from specific folders etc.
I upload all of that to Google Drive.
Somehow run that program from Google Drive and if you can make the user not to realise it that it is from Google Drive than it is even better (log in interface etc)
I would like to know if one of the next solutions are possible or there is another way:
run the exe directly from Google Drive (oh, naivity, or perhaps there is something there I don't see)
run the exe from Google Drive with the help of another python code which can be on your computer but does nothing more than log in to Google and Run the exe from the right folder or download it to temporary and run it from there automatically.
using Google Drive as Windows Service so I guess you can use it as a simple partition of your computer and run the program from there Here is a better description
perhaps avoiding Google as it is and use some kind of encrypting (though I understood it's not really for python)
Becuase my python program has already more then 20000 lines of code and uses about 20 python libraries and needs to load formats as jpg, png, csv (spreadsheets) (etc.) I don't think that Google App Engine is enough. Though I'm quite a noob here so I can be very very wrong.
I hope I made myself clear and please just give me a lead if you can. The right way to go about this and I do my homework. I would really appreciate it.
Consider renting an EC2 Windows instance. Set it up with all the libraries you'll require.

Categories

Resources