python-2.7

How to identify character encoding from website?

ぐ巨炮叔叔 提交于 2021-02-09 11:14:06
问题 What I'm trying to do: I'm getting from a database a list of uris and download them, removing the stopwords and counting the frequency that the words appears in the webpage, then trying to save in the mongodb. The Problem: When I try to save the result in the database I get the error bson.errors.invalidDocument: the document must be a valid utf-8 it appears to be related to the codes '\xc3someotherstrangewords', '\xe2something' when I'm processing the webpages I try remove the punctuation,

socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host (python2.7)

十年热恋 提交于 2021-02-09 11:12:29
问题 I have a problem with my socket , it is well functioning but when i close the client / close the client window the server lost the connection ( the server needs to stay open and wait for other connection) while True: rlist, wlist, xlist = select.select([server_socket]+open_client_sockets, open_client_sockets, []) for current_socket in rlist: if current_socket is server_socket: (new_socket, address) = server_socket.accept() open_client_sockets.append(new_socket) print 'new member : ' + str

socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host (python2.7)

白昼怎懂夜的黑 提交于 2021-02-09 11:11:58
问题 I have a problem with my socket , it is well functioning but when i close the client / close the client window the server lost the connection ( the server needs to stay open and wait for other connection) while True: rlist, wlist, xlist = select.select([server_socket]+open_client_sockets, open_client_sockets, []) for current_socket in rlist: if current_socket is server_socket: (new_socket, address) = server_socket.accept() open_client_sockets.append(new_socket) print 'new member : ' + str

socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host (python2.7)

旧街凉风 提交于 2021-02-09 11:11:07
问题 I have a problem with my socket , it is well functioning but when i close the client / close the client window the server lost the connection ( the server needs to stay open and wait for other connection) while True: rlist, wlist, xlist = select.select([server_socket]+open_client_sockets, open_client_sockets, []) for current_socket in rlist: if current_socket is server_socket: (new_socket, address) = server_socket.accept() open_client_sockets.append(new_socket) print 'new member : ' + str

Django point ImageField to an already existing image

梦想与她 提交于 2021-02-09 09:22:06
问题 I have a model which has an Image field: class Foo(models.Model): image = models.ImageField(upload_to = "bar", blank = True) I am downloading an image over the internet using urllib like this: urllib.urlretrieve(img_url, img_path) Now I want to point the Image field to this downloaded image saved as img_path. I have tried using Image.open() from PIL to first open the file and point to it and obj.image.save(File(open(file_path))) using django.core.files.File but they don't seem to work. Is

Django point ImageField to an already existing image

我的未来我决定 提交于 2021-02-09 09:19:55
问题 I have a model which has an Image field: class Foo(models.Model): image = models.ImageField(upload_to = "bar", blank = True) I am downloading an image over the internet using urllib like this: urllib.urlretrieve(img_url, img_path) Now I want to point the Image field to this downloaded image saved as img_path. I have tried using Image.open() from PIL to first open the file and point to it and obj.image.save(File(open(file_path))) using django.core.files.File but they don't seem to work. Is

django.db.utils.ProgrammingError: relation already exists on OenBSD vps

℡╲_俬逩灬. 提交于 2021-02-09 06:48:34
问题 I am getting this error. I tried with migrate --fake default but it doesn't seems to be working. attached is output of "python manage.py migrate" My set up is Django 1.6 + celery3.1.12 + postgresql + gunicorn on OneBSD VPS. Running migrations for users: - Migrating forwards to 0007_auto__del_field_profile_weekly_digest__del_field_profile_daily_digest_. > users:0001_initial FATAL ERROR - The following SQL query failed: CREATE TABLE "users_user" ("id" serial NOT NULL PRIMARY KEY, "password"

Python Numpy Loadtxt - Convert unix timestamp

。_饼干妹妹 提交于 2021-02-09 04:57:16
问题 I have a text file with many rows of data - the first piece of data in each row is a unix timestamp such as 1436472000 . I am using numpy.loadtxt and in the parameters for converters I want to specify for it to convert the timestamp into whatever numpy understands as a date time. I know this needs to go after the 0: in the curly brackets, but I can't work out how to convert it. I know a converter can be used from matplotlib.dates.strpdate2num for normal dates, but I this won't work for unix

Creating Virtual environment using python 3.8 when python 2.7 is present

时间秒杀一切 提交于 2021-02-09 01:55:34
问题 I am trying to create a virtual environment using mkvirtualenv with python 3 in Windows but the environment is created with python 2.7.My pip version is also from python 2.7 which i have avoided using py -m pip install virtualenvwrapper-win When i do mkvirtualenv test environment is created with python 2.7 Please help me with a solution Thanks in advance:) 回答1: If you would like to create a virtualenv with python 3.X having the version 2.X You just have to pass a parameter argument for your

To drop an index with psycopg2 takes effect before or after commit?

浪子不回头ぞ 提交于 2021-02-08 20:54:14
问题 I'm doing a python script to insert several data into a postgresql database. Following the postgresql documentation in order to speed up the load process my script has this sort of structure Connect to the database and create a cursor Drop all the indexes Load all the data using the 'copy' command Recreate back all the indexes Commit and close of the cursor and connection (only commit in the whole script) So my question is: Is dropping the indexes before the commit, taking any effect in terms