I perfectly followed all the steps in this documentation :
https://django-debug-toolbar.readthedocs.io/en/latest/installation.html
and tried these solutions I found online
adding to the settings module:
if DEBUG:
import mimetypes
mimetypes.add_type("application/javascript", ".js", True)
def show_toolbar(request):
return True
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': show_toolbar,
}
if DEBUG:
import socket # only if you haven't already imported this
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [
ip[: ip.rfind(".")] + ".1" for ip in ips] + ["127.0.0.1", "10.0.2.2"]
but no luck
any suggestions?
I solved the problem by changing the browser. I was using google chrome but when I switched to edge the problem was solved
Related
I am using docker and the debug toolbar gives the following error:
BaseConnectionHandler.all() got an unexpected keyword argument 'initialized_only'
I wrote the following code in the settings.py file :
if DEBUG:
MIDDLEWARE += [
'debug_toolbar.middleware.DebugToolbarMiddleware',
]
INSTALLED_APPS += [
'debug_toolbar',
]
import os
import socket
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[: ip.rfind(".")] + ".1" for ip in ips] + ["127.0.0.1", "10.0.2.2"]
I wrote the following code in the urls.py file :
if settings.DEBUG:
import debug_toolbar
urlpatterns += [
path('__debug__/', include(debug_toolbar.urls)),
]
For some reason django-debug-toolbar==3.5.0 broke backward compatability with Django lower than 4.1b1.
In 3.5.0 next changes were added:
https://github.com/jazzband/django-debug-toolbar/commit/4b77ec74f2d326013d715453d7a2219e574c3f6a#diff-72ecd973e54107d746eff0947206cbdbe24cbb3c42216b00615e64d49ca70d73R216-R217
But those changes need this changes in Django 4.1b1 to work:
https://github.com/django/django/commit/4f92cf87b013801810226928ddd20097f6e4fccf#diff-dbe1d4538efcca9f9a6157d5d3de919e0844835a7ccc698bb8c5d4a9eb06e274R75-R81
Fix the version of django-debug-toolbar to 3.4.0 before issue is solved. Opened issue in github:
https://github.com/jazzband/django-debug-toolbar/issues/1645
UPD: Django 3.2.4+ will also work and thats probably better solution.
I was programming myself a pretty nice api to get some json data from my gameserver to my webspace using json,
but everytime i am sending a request using angular i am getting this:
127.0.0.1 - - [20/Mar/2018 17:07:33] code 400, message Bad request version
("▒\x9c▒▒{▒'\x12\x99▒▒▒\xadH\x00\x00\x14▒+▒/▒,▒0▒\x13▒\x14\x00/\x005\x00")
127.0.0.1 - - [20/Mar/2018 17:07:33] "▒\x9dtTc▒\x93▒4▒M▒▒▒▒▒\x9c▒▒{▒'\x99▒▒▒▒H▒+▒/▒,▒0▒▒/5"
HTTPStatus.BAD_REQUEST -
127.0.0.1 - - [20/Mar/2018 17:07:33] code 400, message Bad request syntax
('\x16\x03\x01\x00▒\x01\x00\x00\x9d\x03\x03▒k,&▒▒ua\x8c\x82\x17\x05▒QwQ$▒0▒▒\x9f▒B1\x98\x19W▒▒▒▒\x00\x00\x14▒+▒/▒,▒0▒\x13▒\x14\x00/\x005\x00')
127.0.0.1 - - [20/Mar/2018 17:07:33] "▒\x9d▒k,&▒▒ua\x8c\x82▒QwQ$▒0▒▒\x9f▒B1\x98W▒▒▒▒▒+▒/▒,▒0▒▒/5"
HTTPStatus.BAD_REQUEST -
127.0.0.1 - - [20/Mar/2018 17:07:33] code 400, message Bad request syntax
('\x16\x03\x01\x00▒\x01\x00\x00▒\x03\x03)▒▒\x1e\xa0▒\t\r\x14g%▒▒\x17▒▒\x80\x8d}▒F▒▒\x08U▒ġ▒▒\x06▒\x00\x00\x1c▒+▒/▒,▒0▒')
g%▒▒▒▒\x80\x8d}▒F▒U▒ġ▒▒▒▒+▒/▒,▒0▒" HTTPStatus.BAD_REQUEST -
My api
from flask import Flask, jsonify
from flaskext.mysql import MySQL
from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
cors = CORS(app, resources={r"/punishments": {"origins": "http://localhost:5000" "*"}})
mysql = MySQL()
# MySQL configurations
app.config['MYSQL_DATABASE_USER'] = 'test'
app.config['MYSQL_DATABASE_PASSWORD'] = 'Biologie1'
app.config['MYSQL_DATABASE_DB'] = 'test'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql.init_app(app)
#app.route('/punishments', methods=['GET'])
#cross_origin(origin='localhost:5000',headers=['Content- Type','Authorization'])
def get():
cur = mysql.connect().cursor()
cur.execute('''select * from test.punishments''')
r = [dict((cur.description[i][0], value)
for i, value in enumerate(row)) for row in cur.fetchall()]
return jsonify({'punishments' : r})
if __name__ == '__main__':
app.run()
My client function
export class ApiUserService {
private _postsURL = "https://localhost:5000/punishments";
constructor(private http: HttpClient) {
}
getPosts(): Observable<Punishments[]> {
let headers = new HttpHeaders();
headers = headers.set('Content-Type', 'application/json; charset=utf-8');
return this.http
.get(this._postsURL,{
headers: {'Content-Type':'application/json; charset=utf-8'}
})
.map((response: Response) => {
return <Punishments[]>response.json();
})
.catch(this.handleError);
}
private handleError(error: Response) {
return Observable.throw(error.statusText);
}
}
I had the same error as yours.
My flask server was installed inside respberry-pi and I was trying to access it using https://ip:5000.
The problem was I was using https instead of http.
When I changed it to http://ip:5000, it worked.
I also faced same problem
use only http not https :-
http://ip:portnumber
Recently I also faced this, the problem came from the SSL config on my app.
In my .env I set the SSL_DISABLE to False, then I change it to True.
change SSL_DISABLE=False to SSL_DISABLE=True
So, the point here is are: check your URL, maybe be it something like: https://127.0.0.1:5000, just change it to http://127.0.0.1:5000.
Hope it helps to someone who also facing this issue in the future.
in my case, i was trying to debug SocketIo server running on flask. I was trying to access the server using wss:// which was causing the bad request. Changing it to ws:// resolved the issue.
In my case i resolve the problem reverting flask version to Flask==1.1.4 and jinja dependency to Jinja2==3.0.3
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
import libcloud.security
auth_usr = 'ryan#ccc.sss.com'
auth_pass = '*********'
auth_url = 'https://ccc.sss.com:5000/v2.0'
project_name = 'POC'
region_name = ''
libcloud.security.VERIFY_SSL_CERT = False
provider = get_driver(Provider.OPENSTACK)
conn = provider(auth_usr,
auth_pass,
ex_force_auth_url=auth_url,
ex_force_auth_version='2.0_password',
ex_tenant_name=project_name,
ex_force_service_region=region_name)
images = conn.list_images()
for image in images:
print(image)
Results in the following error:
BaseHTTPError: {"error": {"message": "get_version_v2() got an unexpected keyword argument 'auth'", "code": 400, "title": "Bad Request"}}
I've also tried stripping the v2.0 from the url and also adding /tokens. Neither work, and they result in a "cannot find endpoint" error.
I'm using vmware integrated OpenStack.
OK turns out in my case that you need to set the region to "nova" for it to work.
ex_force_service_region="nova"
I had to trace through the code in pyDev to determine that it was the region not matching that was the issue.
I am using OpenLDAP and I would like to connect it to Django using django_auth_ldap. Whatever option I am trying to follow, it never works properly and I can't find the correct solution.
Here are the versions of the various softwares used:
OpenLDAP 20423 (LDAPv3)
Django 1.4.1 or 1.4.3 (I tried with both)
django_auth_ldap 1.1.3
My LDAP directory has a user called noc.noc that I am using to do the test.
I updated my settings.py file with the following lines:
import ldap, logging
from django_auth_ldap.config import LDAPSearch, PosixGroupType
.
.
.
logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
AUTH_LDAP_SERVER_URI = "ldap://ldap.XXX.XX"
AUTH_LDAP_BIND_DN = "cn=<LDAPUSER>,dc=XXX,dc=XX"
AUTH_LDAP_BIND_PASSWORD = "<LDAPPASSWORD>"
AUTH_LDAP_USER_SEARCH = LDAPSearch("dc=XXX,dc=XX",
ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
AUTH_LDAP_GROUP_TYPE = PosixGroupType(name_attr='cn')
AUTH_LDAP_REQUIRE_GROUP = "cn=<USERGROUP>,ou=Groups,dc=XXX,dc=XX"
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=Groups,dc=XXX,dc=XX",
ldap.SCOPE_SUBTREE, "(objectClass=posixGroup)"
)
AUTH_LDAP_USER_ATTR_MAP = {
'first_name': 'givenName',
'last_name': 'sn',
'email': 'mail',
}
And I have the following log message when I try to connect with the noc.noc user on my Django interface:
search_s('dc=XXX,dc=XX', 2, '(uid=%(user)s)') returned 1 objects:
cn=noc.noc,ou=users,dc=XXX,dc=XX
cn=noc.noc,ou=users,dc=XXX,dc=XX is not a member of cn=<USERGROUP>,ou=groups,dc=XXX,dc=XX
Authentication failed for noc.noc
If I remove the line:
AUTH_LDAP_REQUIRE_GROUP = "cn=<USERGROUP>,ou=Groups,dc=XXX,dc=XX"
The connection to the interface works, but it also work with any user in the LDAP database, which is not what I am looking for.
I also checked that the user is well in the ldap database and in the correct group with the following command:
ldapsearch -h 'ldap.XXX.XX' -D 'cn=<LDAPUSER>,dc=XXX,dc=XX' -w '<LDAPPASSWORD>' -b 'cn=<USERGROUP>,ou=Groups,dc=XXX,dc=XX'
And the result is:
# extended LDIF
#
# LDAPv3
# base <cn=<USERGROUP>,ou=Groups,dc=XXX,dc=XX> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#
# <USERGROUP>, Groups, XXX.XX
dn: cn=<USERGROUP>,ou=Groups,dc=XXX,dc=XX
cn: <USERGROUP>
gidNumber: 501
memberUid: cn=user1,ou=Users,dc=XXX,dc=XX
memberUid: cn=noc.noc,ou=Users,dc=XXX,dc=XX
objectClass: posixGroup
# search result
search: 2
result: 0 Success
# numResponses: 2
# numEntries: 1
I tried other parameters in settings.py and look for similar problem on the web but no solution I read solved my problem.
Thanks a lot for your help.
Django-auth-ldap is using the CN to identify a group member instead of the DN. For this reason, the solution is to replace:
cn=noc.noc,ou=Users,dc=XXX,dc=XX
in the memberUid field of the group in LDAP by:
noc.noc
This solves the issue.
Another solution would be to modify the sources of django-auth-ldap. To do so you have to edit the file config.py (found in /usr/local/lib/python2.6/dist-packages/django-auth-ldap on my installation) and find the function called:
def user_groups(self, ldap_user, group_search):
of the class:
class PosixGroupType(LDAPGroupType):
then replace the line:
user_uid = ldap_user.attrs['uid'][0]
by:
user_uid = ldap_user.dn
This should also do the trick.
I have a local development django setup with apache. The problem is that on the deployment server there is no proxy while at my workplace I work behind a http proxy, hence the request calls fail.
Is there any way of making all calls from requests library go via proxy. [ I know how to add proxy to individual calls using the proxies parameter but is there a global solution ? ]
I got the same error reported by AmrFouad. At last, it fixed by updating wsgi.py as follows:
os.environ['http_proxy'] = "http://proxy.xxx:8080"
os.environ['https_proxy'] = "http://proxy.xxx:8080"
Add following lines in your wsgi file.
import os
http_proxy = "10.10.1.10:3128"
https_proxy = "10.10.1.11:1080"
ftp_proxy = "10.10.1.10:3128"
proxyDict = {
"http" : http_proxy,
"https" : https_proxy,
"ftp" : ftp_proxy
}
os.environ["PROXIES"] = proxyDict
And Now you can use this environment variable anywhere you want,
r = requests.get(url, headers=headers, proxies=os.environ.get("PROXIES"))
P.S. - You should have a look at following links
Official Python Documentation for Environment Variables
Where and how do I set an environmental variable using mod-wsgi and django?
Python ENVIRONMENT variables
UPDATE 1
You can do something like following so that proxy settings are only being used on localhost.
import socket
if socket.gethostname() == "localhost":
# do something only on local server, e.g. setting os.environ["PROXIES"]
os.environ["PROXIES"] = proxyDict
else:
# Set os.environ["PROXIES"] to an empty dictionary on other hosts
os.environ["PROXIES"] = {}