I'm trying to access the Gmail API via Python. Here is the instruction.
I have copied the credentials.json (I have also renamed a copy of it and called it token.json and added it into the main folder) and the quickstart.py files in the main folder. I run the quickstart.py in the cmd and using Atom IDE, but I get:
C:\Users\HP Pavilion\AppData\Local\Programs\Python\Python36\lib\site-packages\oauth2client\_helpers.py:255: UserWarning: Cannot access token.json: No such file or directory
warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
Traceback (most recent call last):
File "C:\Users\HP Pavilion\AppData\Local\Programs\Python\Python36\lib\site-packages\oauth2client\clientsecrets.py", line 121, in _loadfile
with open(filename, 'r') as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'credentials.json'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\HP Pavilion\Documents\Atom\Gmail\quickstart.py", line 34, in <module>
main()
File "C:\Users\HP Pavilion\Documents\Atom\Gmail\quickstart.py", line 18, in main
flow = client.flow_from_clientsecrets("credentials.json", SCOPES)
File "C:\Users\HP Pavilion\AppData\Local\Programs\Python\Python36\lib\site-packages\oauth2client\_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\HP Pavilion\AppData\Local\Programs\Python\Python36\lib\site-packages\oauth2client\client.py", line 2135, in flow_from_clientsecrets
cache=cache)
File "C:\Users\HP Pavilion\AppData\Local\Programs\Python\Python36\lib\site-packages\oauth2client\clientsecrets.py", line 165, in loadfile
return _loadfile(filename)
File "C:\Users\HP Pavilion\AppData\Local\Programs\Python\Python36\lib\site-packages\oauth2client\clientsecrets.py", line 125, in _loadfile
exc.strerror, exc.errno)
oauth2client.clientsecrets.InvalidClientSecretsError: ('Error opening file', 'credentials.json', 'No such file or directory', 2)
Seems like the .json files can't be found. They are however in the same folders. I have also tried to run the code as an administrator but without any success.
I am not sure what happened to you but I run the script with either PyCharm or VS Code and it runs perfectly.
The only prerequisite (probably you skipped this step) is that you should first generate the credentials.json file, download it and put it into the same directory where you have the python script. In addition, I created an empty tokens.json file.
First, it will automatically open your default browser to indicate which Gmail account you want to specify. Next, it will output the labels of your Gmail account.
My mistake was that I right clicked on my JSON file, selected rename, then named it credentials.JSON, which made the real file name credentials.JSON.JSON.
If it is in the same location as the script, you can try:
import os
path = os.path.abspath('credentials.json')
with open(path,'r'):
//code
I had the same issue and it turned out that the problem was with the IDE I'm using (Mu 1.1.0). Once I downloaded the JSON file, renamed it, placed it in the directory to where the error was pointing to, and ran everything with cmd, it worked as it should.
Related
My vscode is having problems using the open() function to open a file.
I am trying to open a .txt file. Both the py file and .txt file are in the same folder (named "practice"), but python terminal is erroring out with
File "c:\Users\liamt\OneDrive\Desktop\VSCode\Practice\p2.py", line 4, in <module>
fin = open('ex_text.txt')
FileNotFoundError: [Errno 2] No such file or directory: 'ex_text.txt'
PS C:\Users\liamt\OneDrive\Desktop\VSCode> python -
I tried using the relative path to the .txt file but a permission error came up.
Traceback (most recent call last):
File "c:\Users\liamt\OneDrive\Desktop\VSCode\Practice\p2.py", line 4, in <module>
fin = open('C:\\Users\\liamt\\OneDrive\\Desktop\\VSCode\\Practice')
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\liamt\\OneDrive\\Desktop\\VSCode\\Practice'
PS C:\Users\liamt\OneDrive\Desktop\VSCode>
What am I doing wrong? Really appreciate any help.
When using vscode, open the entire folder/directory containing all the files by using file > open folder, and not just double clicking the python file alone. By opening the entire folder, it is included in the workspace and can be opened by the python file that exists along with it.
I am able to run my exe file but my scripts has multiple pip libraries for it to work. I always get this error when running my script.
Exception in thread Thread-1:
Traceback (most recent call last):
File "threading.py", line 932, in _bootstrap_inner
File "threading.py", line 870, in run
File "AIO_Bot.py", line 265, in main_function
File "cloudscraper/__init__.py", line 665, in create_scraper
File "cloudscraper/__init__.py", line 120, in __init__
File "cloudscraper/user_agent/__init__.py", line 20, in __init__
File "cloudscraper/user_agent/__init__.py", line 77, in loadUserAgent
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/8g/gkf53znx7_7405c26w344ftw0000gn/T/_MEIujM2ll/cloudscraper/user_agent/browsers.json'
Finished in 0.0 second(s)
If anyone knows how to fix this please help!
It seems that your browswers.json is expected to be found in a relative path from the "exe" (cloudscraper/user_agent) when it is not the case when it is really a exe file. You have to modify your pyinstaller build command to include that file in the package. Add
--add-data '/lib/python3.8/site-packages/cloudscraper/user_agent/browsers.json:cloudscraper/user_agent' and it should work. (replace : with ; on Windows)
You can refer to https://pyinstaller.readthedocs.io/en/stable/spec-files.html#adding-data-files for more details.
It seems your script/exe is looking for a file named "browsers.json".
Locate it and try putting it in the same folder as your created *.exe
The file is not being located because you are searching through a path that can not be opened. If your script is on the same level of the path then you would only have to do this
(browsers.json)
to fix this just exclude the directory path
mv /lib/python3.8/site-packages/cloudscraper/user_agent/browsers.json /var/folders/8g/gkf53znx7_7405c26w344ftw0000gn/T/_MEIujM2ll/cloudscraper/user_agent/
if this does not work pip install cloudscraper in terminal instead because pycharms assigniing the file to it's own enviroment
I have a python program which inputs a .wav file name from the user, does some filtering and writes the output to another .wav file. The programs works perfectly well when I run it using the interpreter. But when I run the program using command prompt, it prompts for the input audio filename, but when I type the .wav filename and press enter, I get the following error:
Traceback (most recent call last):
File "C:\python_audio\stereo.py", line 15, in <module>
(fs, x) = read(audio_in,'rb')
File "C:\Python27\Lib\site-packages\scipy\io\wavfile.py", line 155, in read
fid = open(filename, 'rb')
IOError: [Errno 2] No such file or directory: 'chostakovitch.wav'
The python program stereo.py and the .wav file (chostakovitch.wav) are in the path C:\python_audio, and I have added this path as an environment variable.
But I can't figure out why I am still getting this error?
We have an problem with python h5py in debian. The data file is in the same directory as the script file. And i'v tried to give the file test.h5 right with chmod -r and chmod 777.
Error is show up in normal user as in root access.
When we run this script:
## Libarys importeren
import wradlib
#inlezen hdf5 file en config
raw = wradlib.io.read_OPERA_hdf5("test.h5")
We get this error:
root#wxserv:/home/kbroeren# python light.py
Traceback (most recent call last):
File "light.py", line 5, in <module>
raw = wradlib.io.read_OPERA_hdf5("test.h5")
File "/usr/local/lib/python2.7/dist-packages/wradlib-0.1.1-py2.7.egg/wradlib/io.py", line 652, in read_OPERA_hdf5
f = h5py.File(fname, "r")
File "/usr/lib/python2.7/dist-packages/h5py/_hl/files.py", line 150, in __init__
fid = make_fid(name, mode, fapl)
File "/usr/lib/python2.7/dist-packages/h5py/_hl/files.py", line 45, in make_fid
fid = h5f.open(name, h5f.ACC_RDONLY, fapl=plist)
File "h5f.pyx", line 70, in h5py.h5f.open (h5py/h5f.c:1618)
IOError: unable to open file (File accessability: Unable to open file)
root#wxserv:/home/kbroeren#
Can someone help us out with this issue ?
Thank You!
The error appears to be that you either do not have a file called test.h5 in the local directory, or you don't actually have permissions to open it. If the former, create a file called test.h5 for you to work with. But based on the error, it sounds like it may exist, but have permissions like ---------. If so, you might try running chmod u+r test.h5 and rerunning your program.
I have a python script, that should update the program (clear folder and copy new files into it). It works fine, but when I run *.exe file, generated from my script(with py2exe), it gave me an error message:
Traceback (most recent call last):
File "update.py", line 10, in <module>
File "shutil.pyc", line 254, in rmtree
File "shutil.pyc", line 252, in rmtree
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'C:\\Project\\MyProg\\Prog\\app'
Here is my script:
app = 'C:\\Project\\MyProg\\Prog\\app'
update = 'C:\\Project\\MyProg\\Prog\\update'
os.system("taskkill /im file.exe /f")
time.sleep(2)
shutil.rmtree(app)
shutil.move(update, app)
newpath = update
if not os.path.exists(newpath):
os.makedirs(newpath)
with open('info', 'w') as f:
f.write("updated")
subprocess.call(['C:\\Project\\MyProg\\Prog\\app\\file.exe'])
Before you use py2exe on the file, close the script. If you don't see it running, go to your processes list on the task manager and make sure that your script isn't running. It will usually show up as simply python under the description. Just right click and select end process and then confirm.