Tag Archives: Python

You may need to add ‘192.168.55.10’ to ALLOWED_HOSTS.

DisallowedHost at /

Invalid HTTP_HOST header: '192.168.55.10:8000'. You may need to add '192.168.55.10' to ALLOWED_HOSTS.
Request Method: GET
Request URL: http://192.168.55.10:8000/
Django Version: 2.1.8
Exception Type: DisallowedHost
Exception Value:
Invalid HTTP_HOST header: '192.168.55.10:8000'. You may need to add '192.168.55.10' to ALLOWED_HOSTS.
Exception Location: /usr/local/python3/lib/python3.6/site-packages/django/http/request.py in get_host, line 106
Python Executable: /usr/bin/python3
Python Version: 3.6.9
Python Path:
['/www/blog',
 '/usr/local/python3/lib/python36.zip',
 '/usr/local/python3/lib/python3.6',
 '/usr/local/python3/lib/python3.6/lib-dynload',
 '/root/.local/lib/python3.6/site-packages',
 '/usr/local/python3/lib/python3.6/site-packages']
Server time: Monday, 21 October 2019 17:07:12 + 0800

Modify in the project we created setting.py File

ALLOWED_ Hosts = [‘*’], the host requested here is added *

Requested setting INSTALLED_APPS, but settings are not configured. …..DJANGO_SETTINGS_MODULE…..

Python project exception (request to set installed application, but no settings configured). Before accessing settings, you must define the environment variable Django setting module, or call settings. Configure().) :

Requested setting  INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

The solution is as follows:

(1)Run –&> EditConfigures

(2) Find an item in python (Python manage), and then modify the environment variables in it to add an item. The location of the key is Django_ SETTINGS_ Module value is your settingss

Centos7.4 appears Yum command not found [How to Solve]

The purchased ECS runs the yum command, and the yum command not found appears.

By uninstalling Yum and python from the virtual machine, you need to pay attention to the first line of the/usr/bin/Yum file. I define it as “#!/usr/bin/Python”

1. Uninstall Python:

1 rpm -qa|grep python|xargs rpm -e --allmatches --nodeps
2 whereis python|xargs rm -fr

2. Uninstall Yum:

1 rpm -qa|grep yum|xargs rpm -e --allmatches --nodeps
2 rm -rf /etc/yum.repos.d/*
3 whereis yum|xargs rm -fr

3. Create directory Python and Yum to store RPM package:

1 mkdir /usr/local/src/python
2 mkdir /usr/local/src/yum

4. Use WGet to download the RPM package of Python and Yum respectively (Note: it must correspond to the version number of the system)

(1) Download the RPM package of Python:

1 #cd /usr/local/src/python 
2 
3 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-2.7.5-34.el7.x86_64.rpm
4 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
5 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-pycurl-7.19.0-17.el7.x86_64.rpm
6 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-devel-2.7.5-34.el7.x86_64.rpm
7 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-libs-2.7.5-34.el7.x86_64.rpm
8 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-urlgrabber-3.10-7.el7.noarch.rpm
9 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/rpm-python-4.11.3-17.el7.x86_64.rpm

(2) Download RPM package from Yum:

1 #cd /usr/local/src/yum 
2 
3 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-3.4.3-132.el7.centos.0.1.noarch.rpm
4 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
5 #wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm

5. Install the RPM package of Python and yum

(1) Install Python:

1 #cd /usr/local/src/python 
2 
3 #rpm -ivh python-* rpm-python-* 
4   Dependency problems with the installation package occur, at which point the following solution can be found.
5 
6 #rpm -ivh python-* rpm-python-* --nodeps --force
7 --nodeps --force is to force installation regardless of dependencies.
8 
9 Once installed, you can run python:

(2) Install Yum:

1 #cd /usr/local/src/yum 
2 #rpm -ivh yum-*

6. Zigzag conversion

English Title: the string "paymailing" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legitimacy)

Chinese understanding is to give a string and a number, fill the string into the inverted Z-shaped input string, read the characters according to the column, get a new character, and output the character.

For example: string “paypalischiring”, 3

1 P   A   H   N
2 A P L S I I G
3 Y   I   R

My solution is to straighten the inverted Z-shape. It is not difficult to find that the number of lines corresponding to the string is 1232123… We need two variables, one is the index ‘I’, which is used to say that the corresponding character is added to the nth line, and the other is used to control the direction ‘n’. If it is less than the maximum number of lines, then n + 1, if it is equal to the maximum value, then change the direction n – = 1, Index I is added up until the whole string is filled.

My problem-solving code is as follows, there are many places to optimize, just to provide a general idea:

 1 class Solution(object):
 2     def convert(self, s, numRows):
 3         if numRows == 1:
 4             return s
 5         ldict = {}
 6         for i in range(1,numRows+1):
 7             ldict[i] = ''
 8         n = 1
 9         i = 0
10         while i < len(s):
11             while n < numRows:
12                 if i == len(s):
13                     break
14                 ldict[n] += s[i]
15                 n +=1
16                 i +=1
17             while n &> 1:
18                 if i == len(s):
19                     break
20                 ldict[n] += s[i]
21                 n -= 1
22                 i += 1
23         out = ''
24         for i in ldict.values():
25             out +=i 
26         return out

Error in installing Python 3.7 in CentOS 7.6 zipimport.ZipImportError : can’t decompress data; zlib not available

Problem description

In CentOS 7.6, when you execute make install with Python 3.7.3 source code, the following error will be reported:

(cd /usr/local/share/man/man1; ln -s python3.7.1 python3.1)
if test "xupgrade" != "xno"  ; then \
	case upgrade in \
		upgrade) ensurepip="--upgrade" ;; \
		install|*) ensurepip="" ;; \
	esac; \
	 ./python -E -m ensurepip \
		$ensurepip --root=/ ; \
fi
Traceback (most recent call last):
  File "/home/Python-3.7.3/Lib/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/Python-3.7.3/Lib/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/Python-3.7.3/Lib/ensurepip/__main__.py", line 5, in 
    sys.exit(ensurepip._main())
  File "/home/Python-3.7.3/Lib/ensurepip/__init__.py", line 204, in _main
    default_pip=args.default_pip,
  File "/home/Python-3.7.3/Lib/ensurepip/__init__.py", line 117, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/home/Python-3.7.3/Lib/ensurepip/__init__.py", line 27, in _run_pip
    import pip._internal
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1

System version

[root@devEnv ]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

Python version

Python-3.7.3

Questions

Solutions

yum install zlib zlib-devel -y