Category Archives: Python

CSRF verification failed. Request aborted [How to Solve]

On the page of Django project, when submitting the form post request, an error will be reported: CSRF verification failed. Request aborted

You need to add: {% CSRF} to the form_ Token%} can be solved

Such as

1 <form action=""  method="post" enctype="multipart/form-data">
2      {% csrf_token %}
3      <div>
4          import Exl<input type="file" name="exl_obj">
5          <input type="submit" value="upload to server">
6      </div>
7 </form>

[Solved] Pandas Read CSV Error: TypeError: Empty ‘DataFrame’: no numeric data to plot

Simple code, using the panda module to read the CSV data file, there are two ways, one is abandoned by the new version of panda series. From_ csv; The other is panda. Read_ csv

First of all, the problem is that when reading a CSV file, the default data is object type, so there is no character type data to plot. At this time, you only need to convert the type, as follows:

from pandas import Series
import matplotlib.pyplot as plt
data = Series.from_csv('daily.csv',header=0)
#print(data.head())
data.astype(float)
data.plot()
plt.show()

To solve this problem perfectly, the following figure is drawn:

This is the desired result, so the other is panda. Read_ CSV, you are not so lucky. You will find this kind of data stored in CSV:

1981/1/1,20.7
1981/1/2,17.9
1981/1/3,18.8
1981/1/4,14.6
1981/1/5,15.8
1981/1/6,15.8
1981/1/7,15.8
1981/1/8,17.4
1981/1/9,21.8
1981/1/10,20
1981/1/11,16.2
1981/1/12,13.3
1981/1/13,16.7
1981/1/14,21.5

It can’t be displayed as X-axis label, so I changed the first column to 1981… To solve the problem. At this time, of course, we don’t recommend using the second method. If it’s so troublesome, we can use pandas to draw directly by PLT

Finally, we must pay attention to whether the data is abnormal. Some abnormal data are text exceptions, while some may be semantic exceptions. We need to mine and remove the abnormal data. This is often very important. Of course, drawing is often one of the more intuitive ways

Pyspider Install ERROR: Complete output from command python setup.py egg_info:…

is learning the pyspider framework, and the installation process is not smooth. Then Baidu solved the problem and recorded the solution for backup

Problem Description:

First, the PIP version is low. Upgrade according to the prompt

Install again and report the error as follows

solution process:

Step 1: install wheel first

Install with the command PIP3 install wheel

Step 2: install the corresponding version of pycurl

First, download the package to local: https://www.lfd.uci.edu/~gohlke/pythonlibs/

Installation:

Step 3:

Successful re installation: PIP3 install pyspider PIP3

test

The module can be imported normally

Ubuntu16.04 Install python-ldap error: command ‘x86_64-linux-gnu-gcc’ failed with exit status 1

First perform:

sudo apt-get install libldap2-dev
sudo apt-get install libsasl2-dev

Then execute, OK:

pip install python-ldap

参考博文内容:

These are the steps to be followed to install python-ldap in Ubuntu. At first,

sudo apt-get install python-ldap

would throw the following error

In file included from Modules/LDAPObject.c:4:0:
Modules/common.h:10:20: fatal error: Python.h: No such file or directory compilation terminated.
error: command 'gcc' failed with exit status 1

To get past this error, we need to install python-dev package

sudo apt-get install python-dev

After installing that we ll get the following error

In file included from Modules/LDAPObject.c:9:0:
Modules/errors.h:8:18: fatal error: lber.h: No such file or directory
compilation terminated.

To get past this error, we need to install ldap2-dev package

sudo apt-get install libldap2-dev

After installing that we ll get the following error

Modules/LDAPObject.c:18:18: fatal error: sasl.h: No such file or directory compilation terminated.
error: command 'gcc' failed with exit status 1

To get past this error, we need to install libsasl2-dev package

sudo apt-get install libsasl2-dev

After that

sudo apt-get install python-ldap

should install python-ldap without any problems.

Python error: Unable to find vcvarsall.bat [How to Solve]

Python error: Unable to find vcvarsall.bat

Solution 1: install VS2008 (measured)

There is no brain flow completely. After installation, the problem can be solved directly

Solution 2: install VS2010 (not tested)

The last time I installed a VS2010 on my computer, it couldn’t solve the problem as directly as VS2008. I found the following solution from the Internet, I don’t know if it is feasible

Open “& lt; Python installation directory & gt\ Lib\distutils\msvc9compiler.py”

Find toolskey = “vs% 0. F0comntools”% version, and directly modify it to toolskey = “vs100comntools”

Solution 3: install MinGW (measured)

1. Download and install MinGW at: http://sourceforge.net/projects/mingw/files/latest/download?source=files

2. In the installation directory of MinGW, find the bin folder, find mingw32-make.exe, and make a copy of it and change it to make.exe

3. Add the path of MinGW to the environment variable path. For example, if I install MinGW to D:: MinGW, I will add D:: MinGW \ \ bin to the path

4. In & lt; Python installation directory & gt\ Add the file distutils.cfg to distutils, and enter it in the file

[build]

compiler=mingw32

Preservation

5. After performing the original module installation, it is found that an error is still reported. The content of the error is: error: Command ‘GCC’ failed: no such file or directory. The solution is to add D:// MinGW/lib to the path

6. If error: could not find ‘OpenSSL. Exe’ appears during the installation, go to http://pypi.python.org/pypi/pyOpenSSL/0.13 Download and install

When installing the module again, the following error was found:

D:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall “-ID:\Program Files\Python27\inc

lude” “-ID:\Program Files\Python27\include” “-ID:\Program Files\Python27\PC” -c

../libdasm.c -o build\temp.win32-2.7\Release\..\libdasm.o

cc1.exe: error:unrecognized command line option ‘-mno-cygwin’

error: command ‘gcc’ failed with exit status 1

The reason is that – MnO cygwin is no longer accepted by GCC 4.6. X. in order to solve this problem, we need to modify & lt; Python installation directory & gt\ Distutils file. Find:

self.set_ executables(compiler=’gcc -mno-cygwin -O -Wall’,

compiler_ so=’gcc -mno-cygwin -mdll -O -Wall’,

compiler_ cxx=’g++ -mno-cygwin -O -Wall’,

linker_ exe=’gcc’,

linker_ so=’%s -mno-cygwin %s %s’

% (self.linker_ dll, shared_ option,

entry_ point))

To be amended as follows:

self.set_ executables(compiler=’gcc -O -Wall’,

compiler_ so=’gcc -mdll -O -Wall’,

compiler_ cxx=’g++ -mno-cygwin -O -Wall’,

linker_ exe=’gcc’,

linker_ so=’%s -mno-cygwin %s %s’

% (self.linker_ dll, shared_ option,

entry_ point))

I talked about three solutions. The installation of visual studio is too huge. I didn’t try it, so I tried the third method. The error of openssl.exe has not been encountered. It should have existed. However, the directory of distutils.cfg file is a little different under python2.7, which is under python27/lib/distutils. Until the last modification, the final error is:

error: expected ‘=’, ‘,’, ‘;’, ‘ asm’ or ‘__ attribute__’ before ‘PyInt_ AsUnsignedLongLongMask’

There is no solution

There is a warning in the middle. Use DOS style path in cygwin and set path cygwin = nodosfilewarning to avoid it

cygwin warning:

MS-DOS style path detected: C:\cygwin\home\ADMINI~1\hadoop\/build/native

Preferred POSIX equivalent is: /home/ADMINI~1/hadoop/build/native

CYGWIN environment variable option “nodosfilewarning” turns off this warning.

Consult the user’s guide for more details about POSIX paths:

http://cygwin.com/cygwin-ug-net/using.html#using -pathnames

12/02/13 10:34:53 INFO namenode.NameNode: STARTUP_ MSG:

python setup.py install build –compiler=mingw32

This command can’t be tried

(20002, b’DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (127.0.0…

python 3.7

pymssql LINKEL RESPONSIBLE 5.6

Resolution: View

https://www.cnblogs.com/springbrotherhpu/p/11503139.html

https://blog.csdn.net/llx1026/article/details/79579572

1 https://sourceforge.net/projects/freetdswindows/ DOWNLOAD freetds IN windows

2. Explorer, cmd progress F:\FreeTDS-1.00-x86\freetds-1.00\bin

3. Monday 23581;>

Questions

Adaptive Server connection failed
OS error 10060, “Unknown error”

Resolution 4

I’m dead.

pymssql for SQL SERVER

Use pymysql instead of mysql.

CONFIG = {
    "host": '127.0.0.1',
    "user": 'erio',
    "pwd": '123',
    'db': 'Library'
}


conn = pymysql.connect(CONFIG['host'], CONFIG['user'],CONFIG['pwd'])

The connection is successful

Python oserror: [errno 22] invalid argument: emergence and solution

 

 1 if __name__ == '__main__':
 2     startime = time.strftime('%H:%M:%S')
 3     print("Start time is: %s" % startime)
 4 # Test path
 5 test_dir = '. /t/test_case'
 6 # Report path
 7 report_dir = '. /t/report/'
 8 
 9 now = time.strftime('%Y-%m-%d_%H:%M:%S')
10 # Create the full report file
11     filename = report_dir + now + '_report.html'
12     fp = open(filename,'wb')

See!! Look at the ninth line, there is a problem with the acquisition time of now!!! Can’t use colon: can’t use colon: can’t use colon: can’t use colon: important things say three times

It is amended as follows:

1 if __name__ == '__main__':
 2     startime = time.strftime('%H:%M:%S')
 3     print("Start time is: %s" % startime)
 4 # Test path
 5 test_dir = '. /t/test_case'
 6 # Report path
 7 report_dir = '. /t/report/'
 8 
 9 now = time.strftime('%Y-%m-%d_%H_%M_%S')
10 # Create the full report file
11     filename = report_dir + now + '_report.html'
12     fp = open(filename,'wb')

[salt.master :2195][ERROR ][6219] Failed to allocate a jid. The requested returner …

Conclusion:

For salt in python2.7 environment, you need to install PIP install MySQL python

For salt in the python 3 environment, PIP should install mysqlclient in the same directory as salt

1. Production environment 3.6, how to adjust this

1. Salt in February 2019

[root@IP ~]# salt-call --versions-report
Salt Version:
           Salt: 2019.2.0
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: 5.6.0
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8.1
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: 1.4.6
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 3.6.8 (default, Aug  7 2019, 17:28:10)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.4.2
            ZMQ: 4.1.4
 
System Versions:
           dist: centos 7.3.1611 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-514.el7.x86_64
         system: Linux
        version: CentOS Linux 7.3.1611 Core
 
[root@IP ~]#

2, python3.6

2, vengeance

2019-11-29 14:59:46,062 [salt.master      :2195][ERROR   ][6219] Failed to allocate a jid. The requested returner 'mysql' could not be loaded.
2019-11-29 14:59:46,063 [salt.transport.zeromq:754 ][ERROR   ][6219] Some exception handling a payload from minion
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/salt/transport/zeromq.py", line 750, in handle_message
    ret, req_opts = yield self.payload_handler(payload)
  File "/usr/lib64/python3.6/site-packages/tornado/gen.py", line 1015, in run
    value = future.result()
  File "/usr/lib64/python3.6/site-packages/tornado/concurrent.py", line 236, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "/usr/lib64/python3.6/site-packages/tornado/gen.py", line 270, in wrapper
    result = func(*args, **kwargs)
  File "/usr/lib64/python3.6/types.py", line 248, in wrapped
    coro = func(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/salt/master.py", line 1064, in _handle_payload
    'clear': self._handle_clear}[key](load)
  File "/usr/lib/python3.6/site-packages/salt/master.py", line 1095, in _handle_clear
    ret = getattr(self.clear_funcs, cmd)(load), {'fun': 'send_clear'}
  File "/usr/lib/python3.6/site-packages/salt/master.py", line 2137, in publish
    payload = self._prep_pub(minions, jid, clear_load, extra, missing)
  File "/usr/lib/python3.6/site-packages/salt/master.py", line 2233, in _prep_pub
    self.event.fire_event({'minions': minions}, clear_load['jid'])
  File "/usr/lib/python3.6/site-packages/salt/utils/event.py", line 744, in fire_event
    salt.utils.stringutils.to_bytes(tag),
  File "/usr/lib/python3.6/site-packages/salt/utils/stringutils.py", line 61, in to_bytes
    raise TypeError('expected bytes, bytearray, or str')
TypeError: expected bytes, bytearray, or str
2019-11-29 14:59:46,065 [tornado.general  :452 ][ERROR   ][6219] Uncaught exception, closing connection.
Traceback (most recent call last):
  File "/usr/lib64/python3.6/site-packages/zmq/sugar/socket.py", line 356, in send_multipart
    _buffer_type(msg)
TypeError: memoryview: a bytes-like object is required, not 'str'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 444, in _handle_events
    self._handle_send()
  File "/usr/lib64/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 487, in _handle_send
    status = self.socket.send_multipart(msg, **kwargs)
  File "/usr/lib64/python3.6/site-packages/zmq/sugar/socket.py", line 363, in send_multipart
    i, rmsg,
TypeError: Frame 0 ('Some exception handling minion ...) does not support the buffer interface.
2019-11-29 14:59:46,065 [tornado.application:632 ][ERROR   ][6219] Exception in callback None
Traceback (most recent call last):
  File "/usr/lib64/python3.6/site-packages/zmq/sugar/socket.py", line 356, in send_multipart
    _buffer_type(msg)
TypeError: memoryview: a bytes-like object is required, not 'str'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.6/site-packages/tornado/ioloop.py", line 886, in start
    handler_func(fd_obj, events)
  File "/usr/lib64/python3.6/site-packages/tornado/stack_context.py", line 274, in null_wrapper
    return fn(*args, **kwargs)
  File "/usr/lib64/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 444, in _handle_events
    self._handle_send()
  File "/usr/lib64/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 487, in _handle_send
    status = self.socket.send_multipart(msg, **kwargs)
  File "/usr/lib64/python3.6/site-packages/zmq/sugar/socket.py", line 363, in send_multipart
    i, rmsg,
TypeError: Frame 0 ('Some exception handling minion ...) does not support the buffer interface

3. Reason:

Again, I was prompted that mysqlpy was not loaded. This time, I did

MySQL environment is also 3.6

Salt is also 3.6

Is the position not together

4. Solution 1:

Unload and reload

[root@IP ~]# pip3 uninstall mysqlclient
[root@IP salt]# pip3 install  mysql-client

There are still problems

5. Solution 2: complete

Maybe it’s not in a directory

PIP installation specified directory https://blog.csdn.net/guotong1988/article/details/61196363

[root@IP salt]# pip3 install --target=/usr/lib/python3.6/site-packages/ mysql-client

6, results: has become