I'm recently learning how to use django as backend, and let react redux handle frontend. But when I try to implement login function in frontend, and post data to api, ConnectionResetError: [Errno 54] occurs.
I used django's User model to create user, and used rest_framework to create API for login. Then, using react with redux as frontend. When user login, it will trigger reducer to implement a login action with axios.post, but the serverside keeps showing errors. When I just login on API view page, it works fine. So I think the problem is with frontend, but I couldn't figure it out.
my API for login
class LoginAPIView(generics.GenericAPIView):
serializer_class = LoginSerializer
def post(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
user = serializer.validated_data
return Response({
"user": UserSerializer(user,
context=self.get_serializer_context()).data,
"token": AuthToken.objects.create(user)[1]
})
my redux action to login
export const login = (username, password) => dispatch => {
const config = {
headers : {
"Content-Type": "application/json"
}
};
const body = {
"username" : username,
"password" : password
}
axios.post("/api/auth/login", body, config)
.then(res => {
dispatch({
type: LOGIN_SUCCESS,
payload: res.data
});
}).catch(err => {
console.log(err);
dispatch({
type: LOGIN_FAIL
})
});
};
And in my Login.js Component
onSubmit = e => {
e.preventDefault;
console.log(this.state.username, this.state.password);
this.props.login(this.state.username, this.state.password);
};
I use onSubmit to trigger event when user hit login button. I include consolo.log to check whether the data get correctly, and it works fine too.
When I check on Redux devTool on Chrome, neither LOGIN_SUCCESS nor LOGIN_FAIL been dispatched. And base on serverside's HTTP 200, I think the problem is not on backend. Somehow, when post succeeds, the frontend can't receive the result.
[03/Aug/2019 19:20:40] "POST /api/auth/login HTTP/1.1" 200 139
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 58167)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 720, in __init__
self.handle()
File "/Users/kyle/Desktop/Todo/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 171, in handle
self.handle_one_request()
File "/Users/kyle/Desktop/Todo/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 179, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer
Update :
My url pattern in user
urlpatterns = [
path('api/auth', include('knox.urls')),
path('api/auth/user', UserAPIView.as_view()),
path('api/auth/register', RegisterAPIView.as_view()),
path('api/auth/login', LoginAPIView.as_view()),
path('api/auth/logout', KnoxViews.LogoutView.as_view(), name='knox_logout')
]
Related
This logs, quite repeatedly, every time my app loads on my computer.
Exception happened during processing of request from ('127.0.0.1', 53597)
Traceback (most recent call last):
File "/usr/local/Cellar/python#3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "/usr/local/Cellar/python#3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/local/Cellar/python#3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/socketserver.py", line 720, in __init__
self.handle()
File "/usr/local/lib/python3.8/site-packages/django/core/servers/basehttp.py", line 174, in handle
self.handle_one_request()
File "/usr/local/lib/python3.8/site-packages/django/core/servers/basehttp.py", line 182, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "/usr/local/Cellar/python#3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/socket.py", line 669, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer
I realize that this has been posted on extensively over the years, but it seems to me that the consensus on the answer is that it could be one of a few things:
(a) Using a .png instead of an .ico in a favicon
(b) Misusing {% static %}
(c) Misusing event.preventDefault()
Unfortunately for me, none of those things have happened in the last few weeks in my teams commits. So I ask, are there other solutions I may be missing? This is a result of me recently merging with a master development branch.
As I mentioned over here, I had this issue show up while debugging POST DRF api endpoints.
The solution was to add SITE_URL to settings with my localhost and dev server port set, i.e.
SITE_URL = "http://localhost:4000"
Commonly this error is associated with a missing favicon file. But I'm not sure if this change gets around that issue or is due to something else.
For added context, I hit this error while using Pycharm's http request scratch file to debug and validate DRF (django rest framework) endpoints.
The format I was using was:
### Send POST request with json body
POST http://localhost:4000/api/admin/add_node/
Content-Type: application/json
Authorization: Basic admin password
{
"name": "node01",
"username": "username",
"password": "password"
}
My step:
Get Authorization code:I use this URL to get auth code
https://www.gstatic.com/bigquerydatatransfer/oauthz/auth?clientId=<id from list data sources>&scope=https://www.googleapis.com/auth/adwords%20https://www.googleapis.com/auth/bigquery
Create a service account with Project Owner
Execute sample code:
def run_quickstart():
from google.cloud import bigquery_datatransfer_v1
from google.protobuf.struct_pb2 import Struct
client = bigquery_datatransfer_v1.DataTransferServiceClient()
project = <project-id>
parent = client.location_path(project, 'us')
params = Struct()
params.update({
"customer_id": <customer-id>
})
transfer_config = {
"destination_dataset_id": "test",
"display_name": "test",
"data_source_id": "adwords",
"params": params
}
authorization_code = <authorization_code from step 1>
response = client.create_transfer_config(parent, transfer_config, authorization_code)
print(response)
if __name__ == '__main__':
run_quickstart()
Expect:Data transfer create
But I got the error:
Traceback (most recent call last):
File "/project/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
return callable_(*args, **kwargs)
File "/project/lib/python3.7/site-packages/grpc/_channel.py", line 826, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "/project/lib/python3.7/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.INVALID_ARGUMENT
details = "Request contains an invalid argument."
debug_error_string = "{"created":"#1581747953.387292000","description":"Error received from peer ipv6:[2404:6800:4012:1::200a]:443","file":"src/core/lib/surface/call.cc","file_line":1056,"grpc_message":"Request contains an invalid argument.","grpc_status":3}"
>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "app.py", line 49, in <module>
run_quickstart()
File "app.py", line 40, in run_quickstart
parent, transfer_config, authorization_code)
File "/project/lib/python3.7/site-packages/google/cloud/bigquery_datatransfer_v1/gapic/data_transfer_service_client.py", line 563, in create_transfer_config
request, retry=retry, timeout=timeout, metadata=metadata
File "/project/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py", line 143, in __call__
return wrapped_func(*args, **kwargs)
File "/project/lib/python3.7/site-packages/google/api_core/retry.py", line 286, in retry_wrapped_func
on_error=on_error,
File "/project/lib/python3.7/site-packages/google/api_core/retry.py", line 184, in retry_target
return target()
File "/project/lib/python3.7/site-packages/google/api_core/timeout.py", line 214, in func_with_timeout
return func(*args, **kwargs)
File "/project/lib/python3.7/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.InvalidArgument: 400 Request contains an invalid argument.
I couldn't find which step is wrong. Please kind to help me to figure it out.
--- Update 02-19
#mk_sta
I remove authorization_code then the API could create a transfer, but the transfer couldn't work. It will get an error like this screenshot.
I thought the error is caused authorization_code is used to connect to google ads. Is your transfer work fine?
Reference:
https://cloud.google.com/bigquery-transfer/docs/reference/datatransfer/rest/v1/projects.locations.transferConfigs/create
After revising your code snippet, I've noticed some points to mention:
According to the documentation pages BigQuery Data Transfer Service requires initial service account to own bigquery.admin role in order to inherit bigquery.datasets.update permission:
All users that will create transfers must be granted the
bigquery.admin predefined Cloud IAM role. The bigquery.admin role
includes the following BigQuery Data Transfer Service permissions:
bigquery.transfers.update
bigquery.transfers.get
Whenever you invoke create_transfer_config function, authorization_code is an optional parameter, that might be skipped, launching the different authentication model for transport configuration, depending on the particular user case.
I've tried to execute the above code using service account key associated with my GCP project:
export GOOGLE_APPLICATION_CREDENTIALS="<some_path>/[FILE_NAME].json"
I've made a few adjustments to the source code in order to get rid of authorization_code in the transfer config:
def run_quickstart():
from google.cloud import bigquery_datatransfer_v1
from google.protobuf.struct_pb2 import Struct
client = bigquery_datatransfer_v1.DataTransferServiceClient()
project = <project-id>
parent = client.location_path(project, 'us')
params = Struct()
params.update({
"customer_id": <customer-id>
})
transfer_config = {
"destination_dataset_id": "test",
"display_name": "test",
"data_source_id": "adwords",
"params": params
}
response = client.create_transfer_config(parent, transfer_config)
print(response)
if __name__ == '__main__':
run_quickstart()
And that worked for me and I've successfully received response body:
name: "projects/.../..."
destination_dataset_id: "test"
display_name: "test"
update_time {
seconds: 1582044242
nanos: 441442000
}
data_source_id: "adwords"
next_run_time {
seconds: 1581897600
}
params {
fields {
key: "customer_id"
value {
string_value: "XXXX"
}
}
}
user_id: <user_id>
dataset_region: "us"
I've checked the issue : Is there any way we can access the `shared with me` files in graph API Microsoft using application permission? as it's fairly close to my issue but not exacly, so raising a new issue.
I have a list shared with me by another member of my organisation that I can open and access though browser.
let's say the URL is : https://365.sharepoint.com/teams/IC/Lists/Cult%20Tracker/Allitemsg.aspx#InplviewHash7c06d6bd-0344-43fd-8057-ffc7deeec3f7=ShowInGrid%3DTrue
Now I'm trying to pull this data via python and do some analytics on it.
So, I tried "sharepoint" & "Office365-REST-Python-Client" packages but both didn't work and kept throwing 403.
The codes I have tried are :
from sharepoint import SharePointSite, basic_auth_opener
server_url = "https://<host>365.sharepoint.com/"
site_url = server_url + "teams/IC"
opener = basic_auth_opener(server_url, "slaik#<host>.com", "Abcdefgh")
# also tried domain/slaik as userid
site = SharePointSite(site_url, opener)
for sp_list in site.lists:
print(sp_list.id, sp_list.meta['Title'])
The error i got :
Traceback (most recent call last):
File "C:/Users/slaik/OneDrive - <host>/Migrated from My PC/Documents/Sandeep/Scripts/Python/PycharmProjects/IC_KPI_Report/sharepoint_conect.py", line 10, in <module>
for sp_list in site.lists:
File "C:\Users\slaik\OneDrive - <host>\Migrated from My PC\Documents\Sandeep\Scripts\Python\PycharmProjects\IC_KPI_Report\venv\lib\site-packages\sharepoint\lists\__init__.py", line 80, in __iter__
return iter(self.all_lists)
File "C:\Users\slaik\OneDrive - <host>\Migrated from My PC\Documents\Sandeep\Scripts\Python\PycharmProjects\IC_KPI_Report\venv\lib\site-packages\sharepoint\lists\__init__.py", line 36, in all_lists
result = self.opener.post_soap(LIST_WEBSERVICE, xml)
File "C:\Users\slaik\OneDrive - <host>\Migrated from My PC\Documents\Sandeep\Scripts\Python\PycharmProjects\IC_KPI_Report\venv\lib\site-packages\sharepoint\site.py", line 32, in post_soap
response = self.opener.open(request, timeout=self.timeout)
File "c:\users\slaik\appdata\local\programs\python\python36\Lib\urllib\request.py", line 532, in open
response = meth(req, response)
File "c:\users\slaik\appdata\local\programs\python\python36\Lib\urllib\request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "c:\users\slaik\appdata\local\programs\python\python36\Lib\urllib\request.py", line 570, in error
return self._call_chain(*args)
File "c:\users\slaik\appdata\local\programs\python\python36\Lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "c:\users\slaik\appdata\local\programs\python\python36\Lib\urllib\request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
and
import json
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.runtime.client_request import ClientRequest
from office365.runtime.utilities.request_options import RequestOptions
from office365.sharepoint.client_context import ClientContext
url = "https://<host>365.sharepoint.com/teams/IC"
username = "slaik#<host>.com" #also tried domain/slaik as userid
password = "Abcdefgh"
ctx_auth = AuthenticationContext(url)
if ctx_auth.acquire_token_for_user(username, password):
request = ClientRequest(ctx_auth)
options = RequestOptions("{0}/_api/web/".format(url))
options.set_header('Accept', 'application/json')
options.set_header('Content-Type', 'application/json')
data = request.execute_request_direct(options)
s = json.loads(data.content)
web_title = s['Title']
print("Web title: " + web_title)
else:
print(ctx_auth.get_last_error())
the error i got:
An error occurred while retrieving token: AADSTS50126: Invalid username or password.
An error occurred while retrieving auth cookies
Traceback (most recent call last):
File "C:/Users/slaik/OneDrive - <host>/Migrated from My PC/Documents/Sandeep/Scripts/Python/PycharmProjects/IC_KPI_Report/sharepoint_conect.py", line 30, in <module>
data = request.execute_request_direct(options)
File "C:\Users\slaik\OneDrive - <host>\Migrated from My PC\Documents\Sandeep\Scripts\Python\PycharmProjects\IC_KPI_Report\venv\lib\site-packages\office365\runtime\client_request.py", line 104, in execute_request_direct
self.context.authenticate_request(request_options)
File "C:\Users\slaik\OneDrive - <host>\Migrated from My PC\Documents\Sandeep\Scripts\Python\PycharmProjects\IC_KPI_Report\venv\lib\site-packages\office365\runtime\auth\authentication_context.py", line 35, in authenticate_request
request_options.set_header('Cookie', self.provider.get_authentication_cookie())
File "C:\Users\slaik\OneDrive - <host>\Migrated from My PC\Documents\Sandeep\Scripts\Python\PycharmProjects\IC_KPI_Report\venv\lib\site-packages\office365\runtime\auth\saml_token_provider.py", line 69, in get_authentication_cookie
return 'FedAuth=' + self.FedAuth + '; rtFa=' + self.rtFa
TypeError: must be str, not NoneType
In one answer in stack overflow I got to know that it doesn't work that way anymore and I should use Microsoft graph api.
So, I logged into the api console and provided it Sites.Read.All, Sites.ReadWrite.All among other permissions.
So, now if I try this : Get https://graph.microsoft.com/v1.0/sites?search=IC
I'm getting a response 200:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites",
"value": [
{
"createdDateTime": "2017-05-26T14:04:29Z",
"id": "<host>365.sharepoint.com,fec353b1-bd1a-4569-acd9-6421737b81d6,5b449746-eaae-4941-b044-ef9703a6b2ee",
"lastModifiedDateTime": "0001-01-01T08:00:00Z",
"name": "IC",
"webUrl": "https://<host>365.sharepoint.com/teams/IC",
"displayName": "IC Division - MRC",
"root": {},
"siteCollection": {
"hostname": "<host>365.sharepoint.com"
}
}
]
}
But if I try this :Get https://graph.microsoft.com/v1.0/sites/IC/lists
or this : https://graph.microsoft.com/v1.0/sites/IC/lists/Cult%20Tracker
I get an error:
{
"error": {
"code": "invalidRequest",
"message": "Invalid hostname for this tenancy",
"innerError": {
"request-id": "ab43af0a-6be0-4a40-91ab-5a4ff52bc261",
"date": "2019-10-17T14:05:52"
}
}
}
I'm referring to the doc : https://learn.microsoft.com/en-us/graph/api/resources/list?view=graph-rest-1.0
and not sure what am I missing.
Thanks for reading through this long description and any help you can provide.
You need to use the site id like this
GET /sites/{site-id}
In other words, your URI should be
https://graph.microsoft.com/v1.0/sites/host>365.sharepoint.com,fec353b1-bd1a-4569-acd9-6421737b81d6,5b449746-eaae-4941-b044-ef9703a6b2ee/lists
I am using Python 3.7 with Django 1.11.18. I have to connect to an Oracle 11g database and that is why the use of 1.11 version for django.
The below code was working for django 2.0.7 and python 3.7 but when i downgraded my version to 1.11.18 it s started giving me the error.
I am sending a post request via an HTML form. The post request has fields username and password. The python code to retrieve the same is :-
username = request.POST[‘username’]
password = request.POST[‘password’]
I also tried:-
username = request.POST.get(‘username’, False)
The above code picks up the default value even though a valid valuse is passed through my form.
Any idea why this is happening and how to solve it.
Edit:- The full part of the code is below
views.py
username = request.POST['username']
password = request.POST['password']
user = authenticate(request, username=username, password=password)
if user is not None:
login(request)
request.session['userName'] = username
return HttpResponse("SUCCESS")
else:
return HttpResponse("FAILURE")
HTML
$( "#loginForm" ).submit(function( event ) {
// Stop form from submitting normally
event.preventDefault();
var jqxhr = $.post( "http://127.0.0.1:8000/ScApp2/xxxx/", $( "#loginForm" ).serialize(), function() {
})
.done(function( data ) {
if( data == "SUCCESS")
window.location.href = 'http://127.0.0.1:8000/ScApp2/home/xxxx.html';
else
alert("Please check your username and password and try again.");
})
.fail(function() {
alert( "ERROR : Please contact the Support Team." );
});
});
TRACEBACK:-
[28/Jan/2019 17:12:24] "POST /xxxx/xxxx/ HTTP/1.1" 200 7
Internal Server Error: /xxxx/xxxx/ScorecardApp20/
Traceback (most recent call last):
File "c:\users\xxxx\xxxx\local\programs\python\python37\lib\site-packages\django\utils\datastructures.py", line 83, in __getitem__
list_ = super(MultiValueDict, self).__getitem__(key)
KeyError: 'username'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\xxxx\xxxx\local\programs\python\python37\lib\site-packages\django\core\handlers\exception.py", line 41, in inner
response = get_response(request)
File "c:\users\xxxx\xxxx\local\programs\python\python37\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "c:\users\xxxx\xxxx\local\programs\python\python37\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\PythonWorkspace\xxxx\xxxx\views.py", line 67, in home
username = request.POST['username']
File "c:\users\xxxx\xxxx\local\programs\python\python37\lib\site-packages\django\utils\datastructures.py", line 85, in __getitem__
raise MultiValueDictKeyError(repr(key))
django.utils.datastructures.MultiValueDictKeyError: "'username'"
I am running datastore emulator. When I run "dev_appserver.py app.yaml" command, I get this error
403 Missing or insufficient permissions.
This is the warning I get. I know there is a problem with authentication. I have gone through this. But couldn't end up finding a solution.
Some details:
I am using MySQL databases for some apps.
For others I want to use datastore.
I am running datastore emulator on one tab, Google cloud proxy on another, dev_appserver on the third one.
I have set the environment variables using the command gcloud beta emulators datastore env-init.
My settings.py
if os.getenv('GAE_APPLICATION', None):
# Running on production App Engine, so connect to Google Cloud SQL using
# the unix socket at /cloudsql/<your-cloudsql-connection string>
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/connectionname',
'NAME': 'db_name',
'USER': 'username',
'PASSWORD': 'password',
}
}
else:
# Running locally so connect to either a local MySQL instance or connect to
# Cloud SQL via the proxy. To start the proxy via command line:
#
# $ cloud_sql_proxy -instances=[INSTANCE_CONNECTION_NAME]=tcp:3306
#
# See https://cloud.google.com/sql/docs/mysql-connect-proxy
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '127.0.0.1',
'PORT': '3307',
'NAME': 'dbname',
'USER': 'username',
'PASSWORD': 'password',
}
}
# [END db_setup]
My app.yaml
runtime: python37
handlers:
- url: /static
static_dir: static/
- url: /.*
script: auto
Technology background:
Django 2.1
Python 3.5.2
Stack trace:
Traceback (most recent call last):
File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/salman/chaipani_env/project_chaipani/chaipani/views.py", line 20, in post_new
post = models.insert(data)
File "/home/salman/chaipani_env/project_chaipani/chaipani/models.py", line 15, in insert
client.put(entity)
File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/cloud/datastore/client.py", line 404, in put
self.put_multi(entities=[entity])
File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/cloud/datastore/client.py", line 431, in put_multi
current.commit()
File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/cloud/datastore/batch.py", line 273, in commit
self._commit()
File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/cloud/datastore/batch.py", line 249, in _commit
self.project, mode, self._mutations, transaction=self._id)
File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/cloud/datastore_v1/gapic/datastore_client.py", line 426, in commit
request, retry=retry, timeout=timeout, metadata=metadata)
File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/api_core/gapic_v1/method.py", line 139, in __call__
return wrapped_func(*args, **kwargs)
File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/api_core/retry.py", line 260, in retry_wrapped_func
on_error=on_error,
File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/api_core/retry.py", line 177, in retry_target
return target()
File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/api_core/timeout.py", line 206, in func_with_timeout
return func(*args, **kwargs)
File "/tmp/tmpIZrOSY/lib/python3.5/site-packages/google/api_core/grpc_helpers.py", line 61, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.PermissionDenied: 403 Missing or insufficient permissions.
INFO 2018-10-10 10:51:26,298 module.py:880] default: "POST /users/post/new/ HTTP/1.1" 500 133823
It seems that your Default service account does not have enough permissions. It might require some additional permissions such as "Datastore Index Admin" to infer over a Datastore[1]. I am not sure on how this will work in the Datastore emulator, but since it aims to provide a local emulation, maybe it will get the roles and permission to perform a test. Could you please check the permissions in your service account[2], change if needed and let me know if the issue persists. I will be waiting for your reply.
[1]https://cloud.google.com/appengine/docs/flexible/nodejs/granting-project-access#before_you_begin
[2]https://cloud.google.com/iam/docs/granting-roles-to-service-accounts