AttributeError " 'Call' object has no attribute 'starargs' in CherryPy with Python 3.5 - cherrypy

Short version:
CherryPy seems to break when run under python 3.5. Minimal working example below.
Long version:
I'm using CherryPy to serve a web-based GUI for a little tool I made with a friend. When Python 3.5 was released and I tried running our project with it, it broke. That obviously shouldn't happen.
Now, I've finally had time to investigate and build a minimal working (well, broken) example of the error.
The offending line seems to be in server.conf, Line 10.
server.py
import cherrypy
class WebServer(object):
#cherrypy.expose
def index(self):
return 'This is the index!'
if __name__ == '__main__':
cherrypy.config.update('server.conf')
cherrypy.quickstart(WebServer(), '/', 'server.conf')
server.conf
[global]
server.socket_host: "0.0.0.0"
server.socket_port: 8080
[/]
tools.sessions.on = True
tools.sessions.timeout = 60
tools.staticdir.on = True
tools.staticdir.dir = "static"
tools.staticdir.root = os.path.abspath(os.getcwd())
Static contains this HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>If you can read this, the code works.</title>
</head>
<body>
Plain HTML.
</body>
</html>
Running server.py with Python 3.5 on Ubuntu 15.10 results in the following error:
ValueError: ("Config error in section: '/', option: 'tools.staticdir.root', value: 'os.path.abspath(os.getcwd())'. Config values must be valid Python.", 'AttributeError', ("'Call' object has no attribute 'starargs'",))
For some reason, under Python 3.4.3, os.path.abspath(os.getcwd()) is perfectly valid, but not under Python 3.5...
Can anyone help me out, here?

Related

ExtJs 7 (Community) npm build for Production Not Working

I have an application on ExtJs 7.0.0-CE, it works well locally at webpack-dev-server running with npm run dev, but when I build as production and copy it to IIS doesn't.
I'm building using npm:
npm run build
The result at output is:
What I had observed is that the URL I'm calling is "http://myserver/indicators", but the Ext tries to load using only the base URL "http://myserver/".
The browser console show :
GET http://192.168.10.211/main.js?da2a6a29bf9e7731b19e net::ERR_ABORTED 404 (Not Found)
I think the get should include the virtual path, like:
GET http://192.168.10.211/indicators/main.js?da2a6a29bf9e7731b19e
And the main.js doesn't even exists at the output folder of build
Below I put some config files that may be relevant.
app.json
package.json
Application.js
App.js:
Ext.application({ extend: 'paineis.Application', name: 'paineis'});
The problem was what I suspected, the base url without the virtual path.
The solution was to remove the tag <base href="/"> from Index.html at the root folder of the application before build the application.
From:
<!DOCTYPE HTML>
<html manifest="">
<head><base href="/">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
.
.
.
To:
<!DOCTYPE HTML>
<html manifest="">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
.
.
.
With it removed, worked just fine and all files were found and application worked just fine!

Django and React... Why scripts don't work on the index.html page

I'm trying to study React in the context of Django... React by itself works, Django also works. When I'm trying to work with React in the Django, it doesn't give me any troubles, but nothing is seen on the page.
I tried:
I installed all possible packages from React. I lowered the version of one package, I don't remember exact name of it right now... It gave me some faults, I lowered its version because it automatically installed alfa version.
Originally I installed React into the Django project, but then I realized, it is wrong way to do it and installed React as separate Django project...
I tried to look up if somebody else had the same problem as me, found two threads, I tried solutions, they didn't help unfortunately:
stackoverflow.com/questions/61125436/opening-a-new-react-portal-only-opens-an-empty-page-with-no-content
And one more I cannot find it right now...
I followed this blog:
www.valentinog.com/blog/drf/
My code.
I have to mention. I start node.js in one cmd window with 'npm run dev' and after I start Django project in another cmd window... with 'python manage.py runserver'... Both start without any complaints...
The structure is quite standard, two projects... frontend(React) and sc(Django)...
frontend/src/index.js:
//import App from "./components/App";
import React from 'react';
import ReactDOM from 'react-dom';
import '/static/css/index.css';
import '/src/components/App.js';
import App from './components/App';
import * as serviceWorker from './serviceWorker';
import '/node_modules/bootstrap/dist/css/bootstrap.css';
ReactDOM.render(<App />, document.getElementById('app'));
serviceWorker.unregister();
frontend/src/components/App.js:
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
class App extends Component {
render() {
return (
<div>
<h4>To Do List</h4>
</div>
);
}
}
export default App;
frontend/templates/frontend/index.html(these folders included in settings.py as templates, so Django has to see files in theses folders):
<!DOCTYPE html>
{% load render_bundle from webpack_loader %}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Site</title>
</head>
<body>
<div id="app"></div>
+{% render_bundle 'frontend' %}//the + sign can be seen on the page
</body>
</html>
sc_s/urls.py:
path('front_index/', views.front_index, name='front_index'),
sc_s/views.py:
def front_index(request):
return render(request, 'frontend/index.html')
Please let me know if I forgot some code...

localhost sent an invalid response

Server for PixiJS not working, "localhost sent an invalid response" error when connecting for client side
When I try connecting to the server (http://127.0.0.1:8080) through my chrome browser, I get a page which has this written on it:
"This page isn’t working
localhost sent an invalid response.
ERR_INVALID_REDIRECT"
And it also downloads a file called "download" with it. I have no idea as to why this happens. This "download" file is almost the exact same as the code in my index.html file. The code is the following:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Testing pixi.JS</title>
<!-- The <script> tag's src should be relative to your root directory where your webserver is running -->
<script src="pixi/pixi.min.js"></script>
</head>
<body>
<script type="text/javascript">
let type = "WebGL";
if(!PIXI.utils.isWebGLSupported()){
type = "canvas";
}
</script>
</body>
</html>
<!-- MY INDEX.HTML CODE -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Testing pixi.JS</title>
<!-- The <script> tag's src should be relative to your root directory where your webserver is running -->
<script src="./pixi.min.js"></script>
</head>
<body>
<h1>Hello there!</h1>
<script type="text/javascript">
let type = "WebGL";
if(!PIXI.utils.isWebGLSupported()){
type = "canvas";
}
</script>
</body>
</html>
CODE TYPED INTO CMD AFTER MOVING TO SAME FOLDER AS INDEX.HTML:
npm install http-server -g
http-server
I expected the page to load but it doesn't. I have no idea as to what to do.
If you navigate to the full path it seems to work: http://127.0.0.1:8080/index.html It seems to be some http-server bug.
There are many other local web servers. I suggest browsersync:
npm install -g browser-sync
browser-sync start --server --index index.html
There is a bug, it seems only affect to Windows. You should install a lower version of http-server, 0.9.0 works.
Run the following command
npm install -g http-server#0.9.0
for more info click here.
I tried to connect to a netgear D700 using opera and edge but got the same response. Eventually I used the old 32bit internet explorer and got into the router. Once the firmware was updated I was able to use opera to get into the router.

Node.js and Wavesurfer.js

Up to this point in my studies, I have been able to serve files to my dynamic web pages using Node.js and Express as follows.
app.use(express.static('./public'));
and then linking to files in the public folder.
The Wavesurfer.js documentation stated that a file has to be loaded from a url
Load an audio file from a URL:
wavesurfer.load('example/media/demo.wav');
I'm not to sure I understand what this mean. or how to link a file to wavesurfer.js using node.js
Edit:
I found this from the link Cross origin requests are only supported for HTTP.” error when loading a local file
Node.js
Alternatively, if you demand a more responsive setup and already use nodejs...
Install http-server by typing npm install -g http-server
Change into your working directory, where your some.html lives
Start your http server by issuing http-server -c-1
This spins up a Node.js httpd which serves the files in your directory as static files accessible from http://localhost:8080
Can't I achieve the same using express?
My code:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="waveform"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/wavesurfer.js/1.2.3/wavesurfer.min.js"></script>
<script>
var wavesurfer = WaveSurfer.create({
container: '#waveform',
waveColor: 'violet',
progressColor: 'purple'
});
wavesurfer.load('/public/recordings/o.mp3');
</script>
</body>
</html>
The errors I'm getting:
The AudioContext was not allowed to start. It must be resumed (or
created) after a user gesture on the page.
Access to XMLHttpRequest at 'file:///C:/public/recordings/o.mp3' from
origin 'null' has been blocked by CORS policy: Cross origin requests
are only supported for protocol schemes: http, data, chrome,
chrome-extension, https.
Ok so I think your problem is because you open the .html page in your browser locally (as a file://). Instead, try to load it from your Express server, something like http://localhost:port/some file.html

starting a web server for angular nodejs app

I am taking baby steps into the MEAN stack but can't figure out step 1, how to run my app. What do I use for a development web server and how do I start it in my directory?
If I just launch index.html as a file it will not work.
Here is my code
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<title>My Site</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"> </script>
<link rel="stylesheet" href="style.css">
<script>
document.write('<base href="' + document.location + '" />');
</script>
<script src="app.js"></script>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/3.2.1/css/bootstrap-combined.min.css"
rel="stylesheet">
</head>
<body ng-app="myApp" ng-controller="MainCtrl">
<a class="btn" ng-click="visible = true">Show the Form</a>
<div ng-show="visible">I used to be hidden!</div>
</body>
</html>
app.js
var app = angular.module( 'myApp', [] );
app.controller( 'MainCtrl', function( $scope ) {
$scope.visible = false;
});
If you simply want to explore AngularJS functionality(or any other front end library for that matter), you don't need a Node.js app.
Assuming you already have npm installed just follow these simple steps:
npm install http-server -g
go from your console to the folder containing your html files
enter http-server -c-1 -p 9000
That would start a simple web server on port 9000 with no caching on your specified directory.
Then simply go to http://0.0.0.0:9000/your_page.html from a browser and voila.
If you want to explore more options on http-server
This code can run without a http server, just in the browser. Note that you are using a really outdated version of Angular (1.0.3), they just released version 1.3.0.
If you want to run your stuff on a local development server, you could use something like yeoman, which generates the app boilerplate for you and comes with a local node server and a build job (check for example https://github.com/yeoman/generator-webapp or https://github.com/yeoman/generator-gulp-webapp)
If you just want a super easy hhtp server and have python installed you can also use python -m SimpleHTTPServer to start up an http server in the current folder.
Here is your code in plunker and it works: http://plnkr.co/edit/j2SqmrP1yWqR68Gm3UCn?p=preview
As you are using the MEAN stack, you should probably check node.js to implement your web server. Check http://www.nodebeginner.org/, it should allow you to code a very simple one.

Resources