Azure App Service ModueNotFoundError opencensus - flask

I am trying to use application insights inside of a flask app using:
from opencensus.ext.azure.log_exporter import AzureLogHandler
but the runtime throws the following error:
ModuleNotFoundError: No module named 'opencensus'
However it works perfectly fine locally. I don't have anything to investigate next What should I do now?

To add to what Jason shared, please review, https://pypi.org/project/opencensus/ for further troubleshooting of the module including how to export traces.

Related

what file structure should I use for django app on google app engine

I can't get my django app to run on google app engine.
It deploys successfully but throws an error when I try connect to it in my browser.
main.py throws the following error: from wsgi import application as app ModuleNotFoundError: No module named 'wsgi'
I've looked at the question here:
ModuleNotFoundError - No module named 'main' when attempting to start service
I don't know what file structure is 'expected' for my main.py to run without errors.
This is the current structure
--static root file--main.py, app.yaml, etc.
|
voting------------
|
--voting-----------settings.py, wsgi.py, etc.
|
other stuff
my main.py currently reads (voting is the name of my project)
from voting.wsgi import application as app
I have tried voting.voting.wsgi and wsgi also. Please help
Fixed the issue by moving the static root.
Look at this for an example of how to set out the folder structure and where to place the static root: https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard_python37/django

GAE import endpoints "No module named endpoints"

I'm using pycharm to develop appengine. Now i'm trying to use endpoints and I've put
libraries:
- name: pycrypto
version: latest
- name: endpoints
version: 1.0
and then in main.py
import endpoints
But it gives me error
No module named endpoints
I can see the endpoints folder inside the GAE library. Anyone can help?
*EDIT: it is just a matter of IDE (pycharm) cant locate endpoints. The app runs fine and okay both in dev server or cloud server. There is a picture just to make it a bit clearer:
Thanks
You need to add {GAE_SDK}/lib/endpoints-1.0, not just the SDK itself. The reason you can import google is because it is directly under {GAE_SDK}. The libraries you specify in app.yaml are laid out differently due to supporting multiple versions. I believe you also need to add {GAE_SDK}/lib/protorpc-1.0/, it's just not showing because there's already an import error.
I'm using the new version of PyCharm Community and I got to config too. You need to set the Source option on each folder like endpoints in File - Setting - Project:
I've run across the following code somewhere which fixes it for me in a client script. I'm not able to say how much of it may be unnecessary. You'd need to edit the google_appengine path for your SDK installation:
sdk_path = os.path.expanduser('~/work/google-cloud-sdk/platform/google_appengine')
try:
import google
google.__path__.append("{0}/google".format(sdk_path))
except ImportError:
pass
try:
import protorpc
protorpc.__path__.append("{0}/lib/protorpc-1.0/protorpc".format(sdk_path))
except ImportError:
pass
sys.path.append("{0}/lib/endpoints-1.0".format(sdk_path))

how to setup a unittest for a web-project

I have problems to properly configure my first unittest in the DartEditor(1.8.5).
I wrote a web-app with Dart that is located in the web-folder.
Now i added a test-folder parallel to web with a file called test.dart:
library dartingflame_test;
import 'dart:math';
import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:mockito/mockito.dart';
import '../web/dartingflame.dart';
void main() {
useHtmlConfiguration();
test("verify robot's direction after move", verifyRobotDirectionAfterMove);
}
void verifyRobotDirectionAfterMove() {...}
Unfortunatly I now have problems to run this test file.
Run with Dartium leads to the message: Unable to locate associated html file
Run leads to: Observatory listening on http://127.0.0.1:49919
The built-in library 'dart:html' is not available on the stand-alone VM.
'package:unittest/html_config.dart': error: line 10 pos 1: library handler failed
import 'dart:html';
Using useVMConfiguration() instead of useHtmlConfiguration() doesn't help. The test execution still complaints about the import 'dart:html';-line in the library under test.
I couldn't find a solution in the "Unit Testing with Dart"-article.
UPDATE (incorporating Günter Zöchbauer's comment)
ok, i created the index.html which invokes test.dart, but now i seem to have a problem with the relative import of the lib under test import '../web/dartingflame.dart';:
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8081/web/dartingflame.dart
An error occurred loading file: http://localhost:8081
You need to create a web page index.html with the test script as script tag an launch it like any Dart web app. You can also run it non-interactively using content_shell. The Dart SDK contains a batch script which downloads and installs content_shell (it is left out of the SDK download to keep a reasonable download size.
There is also a package test_runner available at http://pub.dartlang.org which helps running all tests in the test directory.

Google App Engine Interactive Console: ImportError: No module named models

I have a django project running on my local server under the google app engine python SDK 1.9.7.
I want to run a query in the interactive console. I have a model called Flatpage
I put the seemingly appropriate handler in the app.yaml file, namely:
url: /admin/.*
script: google.appengine.ext.admin.application
login: admin
From the docs i understood that when the local development server is running the interactive console on the admin server would be running in the same environment as the a project. Yet:
the interactive console does not recognize any of my model classes and when i try to import models I get an error: ImportError: No module named models
I have tried adding the local path to the models.py file to the directory as well as various names like app.models, appname.models and projectname.models to no avail.
However. when I copy and paste the models file into the interactive console it works.
Would someone explain how to import the models file into the interactive console,
and, secondly, why the interactive console, which seemingly should already have the models defined when the server starts, needs to have the models defined again, anyway, thanks!
I'm not sure why you're adding that handler to use the console locally, but what I do is use the Development Console (available since last year), which by default runs on port 8000, from there (localhost:8000/console most likely) you can import modules from your project.
For example if you have models.py in the same directory as app.yaml, you should be able to do:
import models
entity = models.Flatpage()
with no problem.

Django Caught an exception while rendering: No module named registration

I seem to have run into a bit of an issue.
I am busy creating an app, and over the last few weeks setup my server to use Git, mod_wsgi to host this app.
Since deploying it, everything seems to be running smoothly however, I had to go through all my files and insert the absolute url of the project to make sure it works fine.
on my local machine
from registration.models import UserRegistration
on server
from myapp.registration.models import UserRegistration
Am I doing something wrong?
And this has also caused an issue for me where I cannot access my django admin interface.
All i get is this: Caught an exception while rendering: No module named registration
Exception Value: Caught an exception while rendering: No module named registration
As far as I am concerned my app has all the relevant urls, but it does not seem to work.
Thank you in advance
The problem is occurring because somehow your local machine is adding the myapp directory to the PYTHONPATH, as well as its parent directory. The way to fix this is to modify your .wsgi script to add both these directories to sys.path:
import sys
sys.path.insert(0, '/path/to/parent')
sys.path.insert(0, '/path/to/parent/myapp')
Read and use improved WSGI script in:
http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html
This will set up environment to better match Django built in development server and you shoud hopefully not see a difference between the two, especially in respect of how Python module search path is handled.