Unable to progress past signup due to media_root permission error - django

I'm attempting to signup for an account on my django site, but I'm running into the following error:
Thumbnail generation failed
Traceback (most recent call last):
File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\versatileimagefield\image_warmer.py", line 117, in _prewarm_versatileimagefield
url = get_url_from_image_key(versatileimagefieldfile, size_key)
File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\versatileimagefield\utils.py", line 216, in get_url_from_image_key
img_url = img_url[size_key].url
File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\versatileimagefield\datastructures\sizedimage.py", line 149, in __getitem__
height=height
File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\versatileimagefield\datastructures\sizedimage.py", line 201, in create_resized_image
path_to_image
File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\versatileimagefield\datastructures\base.py", line 140, in retrieve_image
image = self.storage.open(path_to_image, 'rb')
File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\files\storage.py", line 33, in open
return self._open(name, mode)
File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\files\storage.py", line 218, in _open
return File(open(self.path(name), mode))
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\jason\\Desktop\\staticfiles\\media_root'
I just reinstalled windows 10 while keeping personal files. This error never happened before reinstalling windows 10. I've looked at the folder permissions and can't see anything amiss. Any thoughts on what I can check?
Thanks!

Related

Request Google cloud speech-to-text API gives 503 error?

I ran the following python sample code on this page (you need a private key to run this): https://cloud.google.com/speech-to-text/docs/quickstart-client-libraries
# Imports the Google Cloud client library
from google.cloud import speech
import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'key.json'
# Instantiates a client
client = speech.SpeechClient()
# The name of the audio file to transcribe
gcs_uri = "gs://cloud-samples-data/speech/brooklyn_bridge.raw"
audio = speech.RecognitionAudio(uri=gcs_uri)
config = speech.RecognitionConfig(
encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=16000,
language_code="en-US",
)
# Detects speech in the audio file
response = client.recognize(config=config, audio=audio)
for result in response.results:
print("Transcript: {}".format(result.alternatives[0].transcript))
This results in the following error:
Traceback (most recent call last):
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\grpc_helpers.py", line 57, in error_remapped_callable
return callable_(*args, **kwargs)
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\grpc\_channel.py", line 826, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\grpc\_channel.py", line 729, in _end_unary_response_blocking
raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "failed to connect to all addresses"
debug_error_string = "{"created":"#1614347442.192000000","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":4090,"referenced_errors":[{"created":"#1614347442.192000000","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":394,"grpc_status":14}]}"
>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\retry.py", line 184, in retry_target
return target()
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\grpc_helpers.py", line 59, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.ServiceUnavailable: 503 failed to connect to all addresses
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:/Users/98274/Desktop/carla_ppo/test_connection.py", line 22, in <module>
response = client.recognize(config=config, audio=audio)
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\cloud\speech_v1\services\speech\client.py", line 334, in recognize
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\gapic_v1\method.py", line 145, in __call__
return wrapped_func(*args, **kwargs)
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\retry.py", line 286, in retry_wrapped_func
on_error=on_error,
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\retry.py", line 206, in retry_target
last_exc,
File "<string>", line 3, in raise_from
google.api_core.exceptions.RetryError: Deadline of 120.0s exceeded while calling functools.partial(<function _wrap_unary_errors.<locals>.error_remapped_callable at 0x0000026B56606A68>, config {
encoding: LINEAR16
sample_rate_hertz: 16000
language_code: "en-US"
}
audio {
uri: "gs://cloud-samples-data/speech/brooklyn_bridge.raw"
}
, metadata=[('x-goog-api-client', 'gl-python/3.7.9 grpc/1.31.0 gax/1.23.0 gapic/2.0.1')]), last exception: 503 failed to connect to all addresses
What's the problem? Does it related to internet issue because I am in China? How can I solve it?
I am posting the answer as CommunityWiki to further contribuite to the community.
As discussed in the comment section, the code provided in the documentation is running smoothly. However, you have to make sure that you set your credentials using GOOGLE_APPLICATION_CREDENTIALS so your request is authenticated. Also,the client libraries have to be properly installed.
In #antaressgzz case's the request to the API was being blocked by a firewall rule. Thus, it is a good practice to check these rules, changing them if applicable.

How can I fix "PermissionError: [Errno 13] Permission denied: 'static'"? [duplicate]

This question already has an answer here:
Refering to a directory in a Flask app doesn't work unless the path is absolute
(1 answer)
Closed 4 years ago.
I'm running an apache2 server with flask and mod_wsgi.
In my flask script I have a function that creates new directories:
def updateDir():
dbData = News.query.all()
for row in dbData:
rowLink = createLink(row.id, row.title)
finalPath = "static/img/posts/{}".format(rowLink)
os.makedirs(finalPath, exist_ok=True)
When I try to run the script it shows this traceback:
ERROR in app: Exception on /refresh [GET]
Traceback (most recent call last):
File "/var/www/abc/abc/venv3/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/var/www/abc/abc/venv3/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/var/www/abc/abc/venv3/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/var/www/abc/abc/venv3/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/var/www/abc/abc/venv3/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/var/www/abc/abc/venv3/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/var/www/abc/abc/main.py", line 133, in refresh
updateDir()
File "/var/www/abc/abc/main.py", line 77, in updateDir
os.makedirs(finalPath, exist_ok=True)
File "/usr/local/lib/python3.6/os.py", line 210, in makedirs
makedirs(head, mode, exist_ok)
File "/usr/local/lib/python3.6/os.py", line 210, in makedirs
makedirs(head, mode, exist_ok)
File "/usr/local/lib/python3.6/os.py", line 210, in makedirs
makedirs(head, mode, exist_ok)
File "/usr/local/lib/python3.6/os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: 'static'
I've already given www-data permissions to write to the 'static' folder and it still shows the error.
Feel free to ask questions if I haven't covered everything in order to help me.
Don't use a relative path name. The current working directory of the process will not usually be where your code is. You need to calculate an absolute path relative to some anchor point. See:
http://modwsgi.readthedocs.io/en/develop/user-guides/application-issues.html#application-working-directory

Celery raised unexpected LookUp Error

I am using celery for my django project.
java_path = "/your/Java/jdk/home/java.exe
os.environ['JAVAHOME'] = java_path
st = POSTagger('/your/postagger/models/path/english-bidirectional-distsim.tagger','/your/postagger/jar/file/path/stanford-postagger.jar')
tag = st.tag([key])
here the key is a list of feature words.
I got following errors, when using celery to execute:
raised unexpected:
LookupError('\n\n===========================================================================\nNLTK
`was unable to find the java file!\nUse software specific configuration paramaters or set the JAVAHOME environment`
variable.\n===========================================================================',)
Traceback (most recent call last):
File "/Users/Envs/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/Users/Envs/lib/python2.7/site-packages/celery/app/trace.py", line 438, in __protected_call__
return self.run(*args, **kwargs)
File "/Users/Envs/src/evolvelearning/tasks.py", line 772, in RunProgram
tag = st.tag([key])
File "/Users/Envs/lib/python2.7/site-packages/nltk/tag/stanford.py", line 59, in tag
return self.tag_sents([tokens])[0]
File "/Users/Envs/lib/python2.7/site-packages/nltk/tag/stanford.py", line 64, in tag_sents
config_java(options=self.java_options, verbose=False)
File "/Users/Envs/lib/python2.7/site-packages/nltk/internals.py", line 82, in config_java
_java_bin = find_binary('java', bin, env_vars=['JAVAHOME', 'JAVA_HOME'], verbose=verbose, binary_names=['java.exe'])
File "/Users/Envs/lib/python2.7/site-packages/nltk/internals.py", line 544, in find_binary
binary_names, url, verbose))
File "/Users/Envs/lib/python2.7/site-packages/nltk/internals.py", line 538, in find_binary_iter
url, verbose):
File "/Users/Envs/lib/python2.7/site-packages/nltk/internals.py", line 517, in find_file_iter
raise LookupError('\n\n%s\n%s\n%s' % (div, msg, div))
LookupError:
===========================================================================
NLTK was unable to find the java file!
Use software specific configuration paramaters or set the JAVAHOME environment variable.
===========================================================================
I have set java_path and javahome and I would like to know why still thess errors occur?
my environment is MAC.
The problem is the java_path, should be:
java_path = "/your/Java/jdk/home

Python Beatbox to Salesforce Error Connecting to Salesforce

I just had my computer re-imaged and have Python 2.7.9 (64-bit) installed on my machine. Using PIP I have beatbox 32.1 installed.
When I make the call to connect to Salesforce:
sf_client.login(sf_username, sf_password)
logging.info('Connected successfully')
I receive an error message. I have tried just the normal login credentials which has always worked and have attempted to connect with my token in the password too.
Has anyone run into this error with Python Beatbox and do you know what debugging options I could try to get to the bottom of this?
Traceback (most recent call last):
File "C:\myCode\salesforceload_beatbox.py", line 126, in <module>
sf_client.login(sf_username, sf_password)
File "C:\Python27\lib\site-packages\beatbox\python_client.py", line 76, in login
res = BaseClient.login(self, username, passwd)
File "C:\Python27\lib\site-packages\beatbox\_beatbox.py", line 62, in login
lr = LoginRequest(self.serverUrl, username, password).post()
File "C:\Python27\lib\site-packages\beatbox\_beatbox.py", line 330, in post
raise RuntimeError('No response from Salesforce')
RuntimeError: No response from Salesforce
After digging deeper into this (and debugging the HTTP connection with requests package), I'm failing at this level
Traceback (most recent call last):
File "C:\myCode\SFDC\test_beatbox_call2.py", line 34, in <module>
requests.get(sf_client.login(sf_username, sf_password))
File "C:\Python27\lib\site-packages\beatbox\python_client.py", line 76, in login
res = BaseClient.login(self, username, passwd)
File "C:\Python27\lib\site-packages\beatbox\_beatbox.py", line 78, in login
lr = LoginRequest(self.serverUrl, username, password).post()
File "C:\Python27\lib\site-packages\beatbox\_beatbox.py", line 344, in post
conn.request("POST", path, self.makeEnvelope(), headers)
File "C:\Python27\lib\httplib.py", line 1001, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 1035, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 997, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 850, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 812, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 1216, in connect
server_hostname=server_hostname)
File "C:\Python27\lib\ssl.py", line 350, in wrap_socket
_context=self)
File "C:\Python27\lib\ssl.py", line 566, in __init__
self.do_handshake()
File "C:\Python27\lib\ssl.py", line 788, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)
After searching and googling profusely about TLS connections, etc, I noticed this weekend that my cmd.exe window (which I run the PIP commands from) was launching under C:\Windows\System32> and all of my vms were launching within my personal user directory.
So I searched for my roaming cmd.exe and when I opened that, it was to my personal user directory.
After doing an uninstall and install of beatbox using PIP in the new cmd.exe, all of my Salesforce calls via Beatbox work like they used to.
Now I can't fully explain why this is the case, but something tells me that the certs for this admin location are probably mismatched to my personal certificates. I'm up and running again.

Attempting to use BrowserMobProxy with Selenium, getting permission denied error

Here is the stacktrace:
Traceback (most recent call last):
File "facebook_scraper.py", line 185, in <module>
fb_scraper()
File "facebook_scraper.py", line 36, in fb_scraper
server.start()
File "build/bdist.linux-x86_64/egg/browsermobproxy/server.py", line 56, in start
File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1308, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
I am following instructions from this page
Check that the user running the Python script has the permission to run the browsermob proxy batch file, that should be a .bat file found in path/to/browsermob-proxy
server = Server("path/to/browsermob-proxy")