Tag Archives: python

Python error unhandled exception in thread started by error in sys.excepthook

import time
import thread
def timer(no, interval):
 cnt = 0
 while cnt<10:
 print 'Thread:(%d) Time:%s/n'%(no, time.ctime())
 time.sleep(interval)
 cnt+=1
 thread.exit_thread()
 
def test(): #Use thread.start_new_thread() to create 2 new threads
 thread.start_new_thread(timer, (1,1))
 thread.start_new_thread(timer, (2,2))
 
if __name__=='__main__':
 test()

There is an error
Unhandled exception in thread started by
Error in sys.excepthook:
Original exception was:
Solution: Change the main function to

<pre>if __name__=='__main__':
 test()
time.sleep(3)

As for why sleep for a few seconds, not clear

The message on the Web is that threading is not recommended, use the threading.thread class instead

Urllib2.httperror: http error 403: forbidden solution

When using Python to crawl a web crawler, it is common to assume that the target site has 403 Forbidden crawlers
Question: why are the 403 Forbidden errors
answer: urllib2.httperror: HTTPError 403: Forbidden errors occur mainly because the target website prohibits the crawler. The request header can be added to the request.
Q: So how do you solve it?
answer: just add a headers

req = urllib.request.Request(url="http://en.wikipedia.org"+pageUrl)
HTML = urlopen(req)

to add a headers to make it become

 headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
    req = urllib.request.Request(url="http://en.wikipedia.org"+pageUrl, headers=headers)
    # req = urllib.request.Request(url="http://en.wikipedia.org"+pageUrl)
    html = urlopen(req)

Q: How does Headers look?Answer: you can use the Internet in browser developer tools, such as in firefox
Q: Is there any other problem with pretending to be a browser?
answer: yes, for example, the target site will block the query too many times IP address

Reproduced in: https://www.cnblogs.com/fonttian/p/7294845.html

Indenta in Python tionError:unindent does Error

This Po is reproduced: https://blog.csdn.net/u010412719/article/details/47089473
 
Today in the net copy of a piece of code, the code is very simple, every line looks like the indentation of the indentation, run the time appeared the following error:

[solution]
1. The most common reason for this error is that, indeed, there is no indentation. Depending on the number of lines of error, the code looks fine, there are indenting, and there are no syntax errors.
2. After looking through the code and realizing that nothing really went wrong, it occurred to me to display all the characters in the current Python script (including Spaces and TAB characters) to see if there was any indentation or any other special characters.

Notepad++, the current text editor, has a setting to display all characters.
in:
view — > Display symbol – & GT; Show Spaces and tabs
so you can see whether or not our Python code is indented.

Finally, it turns out that the error is actually caused by the fact that the error line appears to be indented, but actually it is not. This is the root of the problem.
I found a problem that none of the Python code I copied was indent, which requires extra attention when We copy other people’s code. Don’t make it look like your code is indented to feel ok, it’s not actually indented.

How to solve runtime error r6016

2019 Unicorn enterprise heavily recruited Python engineer standard & GT; > >

Insufficient thread data space
The operating system does not give the program enough memory to complete the _BEGINThread call.

When a new thread starts, the library must create an internal database for the thread. When the database cannot be expanded in the memory provided by the operating system, the thread will not start and the processing of the call will stop.
You can try setting your virtual memory a little bit bigger:
Computer attributes –& GT; Advanced – & gt; Performance (Setting)–& GT; Advanced – & gt; Virtual memory (change..)
Set your virtual memory value higher

Reproduced in: https://my.oschina.net/u/2381604/blog/597812

Python keyerror exception

If you don’t know if there’s a key value in dict, you’d better use it

dict.get(key)
If you read with dict[key] it will report a KeyError exception,

Dict. Get method mainly provides a function to return the default value if the value of corresponding key is not obtained.

And dict[key] actually calls the method with ___
D.get(key[, d]) -> D[K] if K in D, else D. defaults to None

Performance Clarke error grid analysis

This is an analysis of the accuracy of the parity blood sugar prediction, as shown in the picture below. A lot of blood sugar monitors will say what’s the probability that our device is level A, which is the area A in the picture below, which is A very good area. In fact, it is very simple to draw such a graph. The Y-axis represents the predicted blood sugar value, and the X-axis is the reference value, which is generally considered to be the accurate value. Generate Clarke error network analysis chart matlab procedures can be private I oh, matlab. As a result of somebody else paper in, so post directly not good.

Error: option — single version externally managed not recognized

When PIP install mysql-connector-Python-RF ==2.1.3, the MAC receives an error message:
error: option –single-version-externally-managed not recognized

The reason may be that your installation package is in wheel format. If you do not have wheels installed on your computer, you will report this error.
Here’s how I solved it:
First install the wheel: PIP Install wheel
Then PIP install the package I want: PIP install mysql-connector-Python-RF ==2.1.3
Solved my problem:

One of the ways to solve the problem of internal server error in flash learning

Recently in learning flask web development, encountered such a problem, is according to the book on the code, run is an Internal server error, because halfway to learn for the sake of convenience, to switch to pycharm to develop, pycharm automatically help me to create a virtual environment, the book says the venv can I do not pollute the environment, but in fact I use, because the initial development on sublime does directly, cause I have a lot of local module, reoccupy pycharm, I changed the environment variable a lot, changed it all to venV, and then this error happened, you can try to delete VENV, use the native environment, and at the same time, change the environment variable back to the native, you can use it. Personal analysis, think should be two environments exist some kind of conflict.

Reproduced in: https://www.cnblogs.com/sgatbl/p/9134283.html

django.core.exceptions . improverconfigured: mysqlclient 1.4.0 or new is required; you have

Django. Core. Exceptions. ImproperlyConfigured: mysqlclient 1.4.0 or newer is required; You have solutions for 0.10.1
An error occurred today when replacing mysql database while learning django:
is written in _init_. Py

import pymysql
pymysql.install_as_MySQLdb()

Error: the django. Core. Exceptions. ImproperlyConfigured: mysqlclient 1.4.0 or newer is required; You have 0.10.1.
This is actually a mismatch between django and Pymysql. Python3 is not supported by mysqldb.
1. Tried to comment the python/Lib/site – packages/django/db/backends/mysql/base. Py files
' ' 'if the version & lt; (1, 4, 0): Raise ImproperlyConfigured(' mysqlClient 1.4.0 or Newer is required; You have %s.' % Database.) '
2. Updated version of Django, also useless
Final solution:
init.py is changed to

import pymysql
pymysql.version_info = (1, 4, 13, "final", 0)
pymysql.install_as_MySQLdb()

Specify the Pymysql version directly
Xiaobai learns Python, if there is a mistake, please give me more advice