How to put a redirect on a xat chat page

Some background
xat is a social networking site where you can, among others, create your own chat. You can approach your chat by following a direct url in the form<your chat page name>

On this page you can customize your layout by adapting the HTML source that is given to you. However, when you try to add certain stuff like javascript, xat will filter your input and replace certain keywords. For example, if you use the word “script” anywhere in your code it will simply be replaced by “nope”. This filtering serves as a protection measure to prevent users from putting malicious code on their chat pages.

In my case, the owner wanted to redirect the chat page to a new website that he recently migrated to.

How to redirect your xat chat page to your website
One way of putting a redirect on an HTML page is by using the usual meta refresh method. However, I found out that the filter currently replaces http-equiv=”refresh” to http-equiv=”fresh”, which obviously breaks the redirect parameter value. However, the filter just replaces “re” with an empty string, which can be trivially bypassed. You just have to use http-equiv=”rerefresh”, which finally replaces it to http-equiv=”refresh”.

So the final result becomes

<meta http-equiv="rerefresh" content="0; url=">

where of course should represent your website where you want to redirect to. Note also that you have to put this between the head tags. The entire HTML code would then look something like this:

<meta http-equiv="rerefresh" content="0; url=">

Final notes
These replacements are in general a bad way of securing a website and should be avoided. As shown above, the current filter the xat developers are applying is useless and is trivially bypassed. I found also other and more advanced ways to accomplish this, but this should in essence do the trick (works on Internet Explorer, Firefox and Chrome). Note that in the future, the xat developers might decide to change the filter by which this small trick will not work anymore. You should also check the xat rules before applying any of this.

Cannot remove old version of Java on Windows


Java can be a pain. Even installing or removing it can sometimes be a problem. There are many common problems you might run into. Below is by no means an extensive list:

Older version of java .. cannot be removed. Contact your technical support group.

Error 1720. There is a problem with this windows installer package. A DLL reguired for this install to complete could not be run. Contact your support personnel or package vendor

Another case is that when trying to install/remove a package, the setup gives the information that it cannot find a necessary .msi file, usually as the following path:

C:\Users\<username>\AppData\LocalLow\Sun\Java\..\.. .msi

This of course does not help a bit because you are unable to get that file or you get even more errors.


This was a real nightmare for me, but I managed to resolve the issue with a Microsoft Fix-It thing. Just download this file:

which is located at this site. Now uninstall all (or the necessary) Java stuff, and retry your install. It should now work like a charm. 🙂

“Python Version 2.7 required which was not found in the registry”

Any module installer that is created using distutils (bdist_wininst) is very likely to produce this error. The problem is that it only detects 32bit installations of Python on 64bit Windows machines. Or more technically, 32bit versions of Python create the following registry path


while 64bits versions create a slightly other registry path which is


When any 32-bit module setup is started (with a Python 64-bit on your system), it first checks whether the first path exists, while instead it should check the second (which does exist).

There are basically three ways of solving this:

  • You can install a 32-bit Python version
  • or install a 64-bit version of your module
  • or adjust the registry such that it really sees that a 64bit Python is installed

I will of course elaborate on the last two options.

Install a 64-bit version of your module

You can find many module binaries here. Choose a 64-bit version and install it. This is the most clean way of fixing the problem.

If your module is not in the list, then try the alternative below.

Fix by adjusting the registry

So the dirty way is to do the following adjustments in the registry:

  1. Run regedit.
  2. Locate the path: HKEY_CURRENT_USER\Software\Wow6432Node\
  3. Create keys in this path: Python\PythonCore\2.7\InstallPath
  4. Modify the “(Default)“, which is initially empty, to the path where Python is located, for example “C:\Python27\”.
  5. You are done. Exit and retry the setup that gave the error.

You can alternatively create a .reg file (for example fix.reg) that will do the above steps automatically. Put exactly the following in it:

Windows Registry Editor Version 5.00

If you are lazy, then you can also download this file, unpack the registry file and just run it.


“Unable to find vcvarsall.bat” error when trying to install lxml

I needed the lxml library on a machine for some python script that I coded earlier. I tried using easy_install by doing

easy_install lxml

but then I got the following error:

Searching for lxml
Best match: lxml 2.3.3
Processing lxml-2.3.3.tgz
Running lxml-2.3.3\ -q bdist_egg --dist-dir c:\users\edin\appdata\local\
Building lxml version 2.3.3.
Building without Cython.
ERROR: 'xslt-config' is not recognized as an internal or external command,
operable program or batch file.

** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt
warning: no files found matching 'lxml.etree.c' under directory 'src\lxml'
warning: no files found matching 'lxml.objectify.c' under directory 'src\lxml'
warning: no files found matching 'lxml.etree.h' under directory 'src\lxml'
warning: no files found matching 'lxml.etree_api.h' under directory 'src\lxml'
warning: no files found matching 'etree_defs.h' under directory 'src\lxml'
warning: no files found matching 'pubkey.asc' under directory 'doc'
warning: no files found matching 'tagpython*.png' under directory 'doc'
warning: no files found matching 'Makefile' under directory 'doc'
error: Setup script exited with error: Unable to find vcvarsall.bat

I tried installing libxml2 and libxslt, but it resulted in similar errors.

Searching for libxml2
Couldn’t find index page for ‘libxml2’ (maybe misspelled?)
Scanning index of all packages (this may take a while)
No local packages or download links found for libxml2
Best match: None
Traceback (most recent call last):
File “C:\Python27\Scripts\”, line 8, in
load_entry_point(‘setuptools==0.6c11’, ‘console_scripts’, ‘easy_install’)()
File “C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\com
mand\”, line 1712, in main
File “C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\com
mand\”, line 1700, in with_ei_usage
File “C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\com
mand\”, line 1716, in
File “C:\Python27\lib\distutils\”, line 152, in setup
File “C:\Python27\lib\distutils\”, line 953, in run_commands
File “C:\Python27\lib\distutils\”, line 972, in run_command
File “C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\com
mand\”, line 211, in run
File “C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\com
mand\”, line 434, in easy_install
File “C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\pac”, line 475, in fetch_distribution
AttributeError: ‘NoneType’ object has no attribute ‘clone’

In one of my previous posts I pointed out how you can solve a similar problem with a missing vcvarsall.bat error, but unfortunately that approach did not solve my problem. Compiling the sources from the ground up was a too intensive job (which I might try to figure out in the future), so I chose the easy path.

The issue was solved by installing these packages from this site which lists a lot of (unoffical) Windows binaries for Python. Everything suddenly started to work as it should. 🙂

Viewstack Transitions in Flex 4

So I’m busy with a project building an Adobe AIR application where at this point I’m working out the layout of the application.

Transitions are usually very simple to accomplish with state transitions, but in my framework of the application I wanted to avoid using states between the different pages that were to be shown. Using transitions on a page defined in a NavigatorContent item within the ViewStack showed to be a syntactically slightly different world.

To cut the story telling, here’s a snippet of code from my project that one can use to accomplish some fading effects on the NavigatorContent within a ViewStack.

The declarations:


and the ViewStack:


where, of course, PageIntro and PageProjects are some defined components not included in this code.

Pretty obvious, isn’t it? 🙂

Calling external programs from Python

The story
I’m currently automating a certain process with a Python script that needs to call external programs with some specific parameters. An additional problem is with this letter s in the word parameters, for my external call requires an execution with more than one argument.

I tried the os.system call but unfortunately it didn’t work on my system because the function was apparently not present. This conclusion followed after I got the error “ImportError: No module named system”. Instead of resolving this error, I  decided to dig into google for some alternatives.  And I did succeed, when I met the lovely miss subproccess. 🙂

Let subprocess do all the calls
To keep it short and skip the syntax explanation, learn from the following example:

import subprocess‘expand -F:* -r’, shell=True)

As you can see, the magic only happens when you pass the string (your complete command) together with the shell=True option.

Happy Python calling. 🙂

Number converter

Once in a while a man wants to convert a hexadecimal number to a decimal one, or even maybe a binary number to a decimal one. Google always helps if you ask “hex 2 bin”, but instead I decided to write an online application of my own.

The converter is implemented as very simple web page and can be found here. On the web page, on the fly conversions are possible between a decimal, hexadecimal and a binary number. So all conversions dec2hex, dec2bin, hex2dec, hex2bin, bin2dec and bin2hex are included in this basic form. See the complete junk of html and javascript code below.

<script type="text/javascript">
  function d2h(d) { return d.toString(16); };
  function h2d(h) { return parseInt(h,16); };
  function d2b(d) { return d.toString(2); };
  function b2d(b) { return parseInt(b,2); };

  function idec(d) {
    // pre: d is int
    document.cform.hex.value = d2h(parseInt(d));
    document.cform.bin.value = d2b(parseInt(d));

  function ihex(h) {
  // pre: h is string
  var d = h2d(h);
  document.cform.dec.value = d;
  document.cform.bin.value = d2b(d);

  function ibin(b) {
    // pre: b is string
    var d = b2d(b);
    document.cform.dec.value = d;
    document.cform.hex.value = d2h(d);

<h1>Number converter</h1>
<p>Insert a decimal, hexadecimal or a binary number to convert it.</p>
<form name="cform">
Decimal: <input name="dec" onkeyup="idec(this.value)" />
Hexadecimal: <input name="hex" onkeyup="ihex(this.value)" />
Binary: <input name="bin" onkeyup="ibin(this.value)" />


How to use cookies with CherryPy


CherryPy uses the Cookie module from Python and in particular the SimpleCookie object type to handle cookies.

Sending a cookie to a browser is accomplished by using cherrypy.response.cookie and receiving a cookie from the browser by cherrypy.request.cookie.


This is demonstrated in the following example code where we use a login and logout procedure :

import cherrypy

class Root(object):
  def index(self):
    return """
""" @cherrypy.expose def doLogin(self, username, password): # Set cookie to send cookie = cherrypy.response.cookie cookie['user'] = username cookie['user']['path'] = '/' cookie['user']['max-age'] = 3600 cookie['pass'] = password cookie['pass']['path'] = '/' cookie['pass']['max-age'] = 3600 return 'Cookie set. You can now logout.' @cherrypy.expose def doLogout(self): # Request cookie that is already set reqcookie = cherrypy.request.cookie # Response cookie that overwrites the old one and expires rescookie = cherrypy.response.cookie for name in reqcookie.keys(): rescookie[name] = name rescookie[name]['path'] = '/' rescookie[name]['max-age'] = 0 # or: rescookie[name]['expires'] = 0 return 'Logged out succesfully. You can now login again.' cherrypy.quickstart(Root())

Download source code

Creating a cookie

It is important to note that

  • cookie[name]
  • cookie[name][‘path’]
  • cookie[name][‘max-age’]

are a bare minimum of attributes that you have to set in order to get this working. If you do not set one of these three attributes, the cookie will simply not be set.

Deleting a cookie

Instead of cookie[name][‘max-age’]=0 you can also use cookie[name][‘expires’]=0, which results in the same effect of deleting the cookie.

“Unable to find vcvarsall.bat” error when trying to install rdflib

Some things just don’t work out like you expect them to do. During my quest with a new web application that I’m about to develop, the very first and basic thing went wrong. The setup of the rdflib python library (version 2.4.2) gave me the following error (on Windows):

“error: Setup script exited with error: Unable to find vcvarsall.bat”

After a lot of useless spent hours on trying to come up with some solution, the answer was found. There is a good solution on the project page of the library too, but I found a slightly quicker solution:

  1. First of all download MinGW. You need g++ compiler and MingW make in setup.
  2. If you installed MinGW for example to “C:\MinGW” then add “C:\MinGW\bin” to your PATH in Windows.
  3. Now start your Command Prompt and go the directory where you have your residing.
  4. Last and most important step: install build --compiler=mingw32

Note: This is all about rdflib version 2.4.2! Version 3.x for example has some major differences with 2.4.2 and so I’m not aware whether the problem there exists and even if it does, i’m not sure if it can be solved by the above solution.

If you have a similar problem but with some other module and you can’t fix it in this way, then you should try this.

Alternative solution

In many other cases it was sufficient to install Visual C++ 2008 Express Edition. You can download it here.