python

Python, UnicodeDecodeError

I get this error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 4: ordinal not in range(128) I tried setting many different codecs (in the header, like # -- coding: utf8 --), or even using u"string", but it still appears. How do I fix this? Edit: I don't know the actual character that's causing this, but since...

How can I generate RSS with arbitrary tags and enclosures

Right now, I'm using PyRSS2Gen to generate an RSS document (resyndicating a modification of an rss feed that was parsed with feedparser), but I can't figure out how to add uncommon tags to the item. items = [ PyRSS2Gen.RSSItem( title = x.title, link = x.link, description = x.summary, guid = x.link, pubDate = datetime...

To understand Python's optparse

Thank you for quack in pointing out the off-by-one! The following code is my first attempt in writing code with Optparse. How can you fix the following bug in getting the help by Optparse? #!/usr/bin/env python import sys import os from optparse import OptionParser e = sys.argv[1] b = sys.argv[2] no = sys.argv[3] def set_figu(figu)...

Separating Business Layer Errors from API errors

The title is horrible, i know; I'm terrible at titles on SO here. I'm wondering what would be the best way to present unified error responses in a webapi when errors could be raised deep inside the application. The errors deep down in the app don't know anything about the web layer (nor should they), so how can the web layer classify m...

how to insert a infomation on a table in Django

This is my form on models.py class ItemForm(forms.Form): itemname = forms.CharField(max_length=100) itemwording = forms.CharField(max_length=100) notes = forms.CharField() abundance = forms.IntegerField(max_value=10) collunit = forms.CharField(max_length=50) litref = forms.CharField(max_length=100) litkey = ...

Read first N lines of a file in python

We have a large raw data file that we would like to trim to a specified size. I am experienced in .net c#, however would like to do this in python to simplify things and out of interest. How would I go about getting the first N lines of a text file in python? Will the OS being used have any effect on the implementation? Thanks :) ...

Plotting Histogram: How can I do it from scratch using data stored in a database?

I have some data stored in a database like this: TableName: faults Table: +------------+--------------+ | fault_type | total | +------------+--------------+ | 1 | 1 | | 2 | 3 | | 3 | 8 | | 4 | 2 | ............................. How am I supposed...

Are there any libraries for Python to simulate keyboard action?

The problem I have is that I have this Python script to launch a application. After the application is launched (the GUI is shown on screen), I want to make it de-activated. It can be done manually by activating another window, or minimizing this app, or pressing the Show Desktop key for WindowsXP. So is there any way that I can do this...

Python won't refresh URL to receive new forex ticker data

Hello, I am trying to save updated Forex ticker data from this website: http://forex.offers4u.biz/TickDBReadDB.php?p=EURUSD just hit refresh to update the ticker. when I use my little python script, it saves the text once, but if i run it again, it makes a new file with the same old data. How can I add a "cachebreaker" so that python...

Find following tag with pyparsing

I'm using pyparsing to parse HTML. I'm grabbing all embed tags, but in some cases there's an a tag directly following that I also want to grab if it's available. example: import pyparsing target = pyparsing.makeHTMLTags("embed")[0] target.setParseAction(pyparsing.withAttribute(src=pyparsing.withAttribute.ANY_VALUE)) target.ignore(pypar...

Redirect realtime common line output to Django HttpResponse

In a long run command line execution, like uncompressing a large .zip archive, how to redirect the realtime output of unzip command to browser via Django's HttpResponse? EDIT: According to paul's suggestion, I did a search and found this question has answers to how to return a HttpResponse by using a generator. http://stackoverflow.co...

django.utils.encoding.DjangoUnicodeDecodeError

I got the following error when tried to add an entry to a Django model via generic relations. django.utils.encoding.DjangoUnicodeDecodeError: 'utf8' codec can't decode byte 0xb8 in position 24: unexpected code byte. You passed in 'ASL/60Styles_Timeless-3_\xb8 CaLe.asl' (<type 'str'>) The model is like this: class MD5(models.Model): ...

Using Numpy to find average value across data sets, with some missing data

I have several (10 or so) CSV-formatted data sets. Each column of a data set represents one aspect of a running system (available RAM, CPU usage, open TCP connections, and so forth). Each row contains the values for these columns at one moment in time. The data sets were captured during individual runs of the same test. The number of r...

checksum udp calculation python

Hi, I'd like to calculate the checksum of an udp header packet I want to send : packetosend = """60 00 00 00 00 24 3a 40 20 02 c0 a8 01 50 00 01 00 00 00 00 00 00 09 38 20 02 c0 a8 01 50 00 01 00 00 00 00 00 00 09 6f""" so i need to join this utf-16 (not a problem) and calculate the checksum of this specific packet. How can i do that ...

Why am I getting this error in python ? (httplib)

if theurl.startswith("http://"): theurl = theurl[7:] head = theurl[:theurl.find('/')] tail = theurl[theurl.find('/'):] response_code = 0 import httplib conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() response_code = int(res.status) http://www.garageband.com/mp3cat/.UZCKbS6N4qk/01_Saraenglis...

How do I move data from local appengine datastore to remote datastore?

I can see how to download the remote datastore to local, and how to upload a CSV to the remote app engine server as outlined here: Uploading and Downloading Data But is there a way to export my local data to a CSV that is ready for the remote upload script? Of course I could write a custom exporter, but is there no way to automate this...

Different response by screen solutions using Django and jQuery

In a thumbnail website, if I want to display 100x100 thumbs on screnn resolutions lower than 1280x1024 while display 150x150 thumbs for screens higher than 1280x1024, is the following procedure correct? Render a page frame with no thumbs by view1() On page frame loaded, it detects client's screen resolution and pass it to another Djang...

Can't call a webservice method using SOAPpy

I am trying to call a webservice using SOAPpy: from SOAPpy import SOAPProxy url = 'http://www.webservicex.net/WeatherForecast.asmx' server = SOAPProxy(url); print server.GetWeatherByPlaceName('Dallas'); print server.GetWeatherByZipCode ('33126'); The server call fails: Traceback (most recent call last): File "soap_test.py", line ...

What is the best way to crawl a login based sites?

I've to automate a file download activity from a website (similar to, let's say, yahoomail.com). To reach a page which has this file download link, i've to login, jump from page to page to provide some parameters like dates etc., and finally click on download link. I am thinking of three approaches: Using WatIN and develop a windows s...

What is the best framework/cms and shopping cart plugin/module/etc. combination?

What is the best framework/cms shopping cart for a beginner php/python developer to implement? I'm potentially going to be developing a site with an online catalog of about one hundred items. Info about the items will change every year. They might add new items. They want to admin their own items and such. I'm afraid that if I use a ...