Posts Tagged ‘Debugging’

Django Error: ‘CSRF verification failed. Request aborted.’

Thursday, June 2nd, 2011

I just got this error when trying to execute a Django application locally. A quick search on the web revealed that I needed to include the following two lines:

'django.middleware.csrf.CsrfViewMiddleware'
'django.middleware.csrf.CsrfResponseMiddleware'

in the ‘MIDDLEWARE_CLASSES’ setting in the Settings.py of the application.

In my setup ‘django.middleware.csrf.CsrfViewMiddleware’ class path was already there, but ‘django.middleware.csrf.CsrfResponseMiddleware’ path was not. I added the latter and it seemed to have resolved the error.

I’m not completely sure what these classes do in detail, but it appears to revolve around security related to the local developing environment and obviously cross-site forgery. I also noticed in the ‘django.middleware.csrf.CsrfResponseMiddleware’ class there are notes that the class was deprecated as of Django 1.4. Once I saw this I removed the path from my Settings.py file, re-ran the application, and it appears to still work. I can’t really explain it, but adding it (at least temporarily) resolved the issue so I thought I would spread the wealth.

Python permission denied error when executing a CGI script

Friday, January 21st, 2011

I’ve just started playing with python with the intent of building android apps. As such this may be obvious to the seasoned python programmer, but nonetheless was not too terribly obvious to me at first.

After creating a CGI script to run I noticed that when the browser would execute the script I would get a 200 OK response from the browser, but the page was empty. Upon checking the terminal I received the following error:

Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/http/server.py”, line 1059, in run_cgi
os.execve(scriptfile, args, env)
OSError: [Errno 13] Permission denied

The solution here is to give the script permission to be executed. To do this run the following line in the terminal (obviously I’m on a mac here):

chmod +x [name of you CGI script]

So just to keep things simple, assume you have a script in your Documents directory named ‘myScript.py’. You would execute the following in the terminal:

Documents myComputer$ chmod +x myScript.py

Essentially, this changes the mode of the specified script to be executable.

One thing to keep in mind, that dumbly wasted a few minutes of my time, is that if you have a terminal window open running the python server you cannot perform the above execution in that window. Make sure you open a new terminal window and execute on the command line.

ORA-00923: FROM keyword not found where expected

Wednesday, December 15th, 2010

This is a general reference to an error I received today when executing an Oracle statement. Essentially the statement was fairly complicated containing a number of subqueries. As such receiving ‘ORA-00923: FROM keyword not found where expected’ as an error in a statement was somewhat frustrating. As it turns out, not only is it a somewhat useless user facing error, it didn’t even turn out to have anything to do with the FROM clause.

After much debugging, a co-worker determined that the issue was a duplicate column reference in the SELECT clause. After determining the point of failure I decided to write up a simple test to determine if this error would be thrown in a statement far less complicated than the one being worked on at the time.

What I learned is rather interesting. This error is only thrown when a column is duplicated, in which the duplicate is contained within the all symbol (*). So on the assumption that the employee_table contains three columns – employee_id, employee_name, and employee_email – let’s take the following example that would throw this error when run against Oracle.

Throws: ORA-00923: FROM keyword not found where expected

SELECT *, employee_name
FROM employee_table

If I were to write out the columns and duplicate the columns I would get a different error. The following example would throw an ambiguous column reference.

Throws: ORA-00918: column ambiguously defined

SELECT employee_id, employee_name, employee_email, employee_name
FROM employee_table

While the above examples are no-brainers, the particular query I was working on was a very complex SQL statement with CF wrappers and Oracle functions and all kinds of good stuff. So under these conditions finding duplicate columns can be very tricky and unfortunately Oracle doesn’t do much to help. So I guess the lesson is that if you get either of these errors check for any duplicating columns. Note that my literal test did contain a JOIN, which may have something to do with the second error listed. That particular statement might throw a different error.

Query Of Queries runtime error. The aggregate function [SUM(expression)] cannot operate on an operand of type [VARCHAR].

Tuesday, December 14th, 2010

I ran into the above error today when trying to run a SUM() function on a query retrieved from a database using the Coldfusion Query of Queries sweetness. While the error itself is fairly explanatory I couldn’t figure out where my column being summed was being typed as a string as opposed to an integer. As such I began reading up in the Coldfusion docs on how to type data columns via a Query of Queries. It turns out that it’s very doable with a Cast() function. So while not using Cast() would throw the above error, using it to cast the column data type as an Integer resolved the issue.

Won’t work while My_Total is a type string (VARCHAR)

SELECT SUM(My_String_Column) AS My_Total
FROM Some_Table

Will work while My_Total is a type string (VARCHAR)

SELECT SUM(Cast(My_String_Column AS INTEGER)) AS My_Total
FROM Some_Table

So, fairly straight-forward usage. Any column can be cast as a number of data types on the fly within the Query of Queries. Just as a side-note, I did resolve the actual issue after discovering the Cast() function. Essentially, I typed my return variable in my Oracle Function as an NVARCHAR2. Hence my value was returning as a string. Once I changed my return data type I no longer needed the Cast() function in my Query of Queries. Nonetheless, it’s pretty cool functionality provided by Coldfusion.

Switch/Case statement constants

Tuesday, November 2nd, 2010

This is more of a note than anything else concerning an error that throws when trying to run a switch case against a variable. Before analyzing this I want to simply display a function that illustrates a working switch statement, and then the same switch statement replacing the case value with a variable. Let’s take a look.

Working switch statement

public boolean function dynamicSwitch()
{
	var data1 = "matthew";
	var data2 = "cook";

	var expression = data1;

	switch(expression)
	{
		case "matthew":
		{
			return true;
		}

		default:
		{
			return false;
		}
	}
}

Throws an error

public boolean function dynamicSwitch()
{
	var data1 = "matthew";
	var data2 = "cook";

	var expression = data1;

	switch(expression)
	{
		case data1:
		{
			return true;
		}

		default:
		{
			return false;
		}
	}
}

So the second example uses the variable ‘data1′ as the value for the case. This throws a Coldfusion error indicating that case values must be constants (a hard-coded value). This makes sense, and maybe you’re wondering why a variable would ever need to be used for the case value. Admittedly, it certainly makes no sense in the above example, but I do personally like to declare all component constants at the top of my component by storing them in a ‘constant’ namespace and prefixing the variable name with a ‘c_’. Coldfusion doesn’t literally support constant variables, so having some rules around how to syntactically declare constant variables in Coldfusion makes sense to me.

So in my case I had set some constant variables in my component, and in a function needed to compare a passed in argument against them. It was a scenario where the value either would or would not equal the value of one of my constants. Hard-coding those values again for a switch statement would have been plain old bad practice. Nonetheless, it was also in this scenario that I learned I could not use a variable for my case value.

The result was that I used an if-else statement instead. It works fine. The switch statement would have been more appropriate, but take what you can get I guess.

String and Integer data typing catch using compare()

Monday, November 1st, 2010

I just previously wrote a post on the loose data typing in Coldfusion and how, although I could see the potential for problems, I have never actually had any issues that I’ve known about due to not having strict data typing. As fate would have it, of course, I ran into an issue today related to data typing using the Coldfusion compare() function. The issue is when two numbers get accidentally typed as a string behind the scenes and it doesn’t become known until you realize that there are inaccuracies in the comparison. It’s very important to note this because it almost made it past me.

The issue occurs when you compare the strings of integers and they get compared not as an integer, but as strings. The difference is that integers get compared as whole numbers, while strings get compared on a character by character basis. So for example comparing the string “3″ and the string “100″ will indicate that “100″ is less than “3″. The reason for this is because when looking at the first character “1″ is indeed less than “3″. Comparing the two as integers will of course indicate that 3 is less than 100.

So speaking more specific, the next thing to note is that the compare() function compares strings. This essentially makes it useless comparing integers. Maybe I’m wrong, but a quick search of the docs didn’t return any comparison function for integers. So the only way I know to handle it is to use an if/else statement. Let’s take a look at what we’re dealing with using the compare() function to compare either integers typed as strings or integers typed as integers, because the compare() function will implicitly type the data as strings.

String Comparison (cfscript)

public void function typeDataCatch()
	displayname="Type Data Catch" hint="Shows a data type catch using compare function." output="false"
{
	var data1 = "2";
	var data2 = "100";

	var dataComparison = compare(data1,data2);  //returns 1 indicating that 100 is less than 2
}

(more…)

Javascript debugging with MS Visual Web Developer 2010 Express

Monday, October 4th, 2010

A colleague of mine let me in on a pretty cool tip today. I think we’ve all been in a position where we needed to debug javascript for IE, but of course IE 6 and 7 do not have built in debuggers. As it turns out the Microsoft Visual Web Developer IDE has a built in javascript debugger for IE7 and 8 (unfortunately I couldn’t get the errors in IE6 to translate to the debugger). To get the debugger you will first need to download the free Visual Web Developer 2010 Express from here.

Once you have the IDE, open the version of IE you will be debugging in and choose Tools > Internet Options. Click the Advanced tab. Make sure that debugging in (Internet Explorer) is unchecked and the Always display errors is checked. Also make sure that you set it as your default browser.

Now open the VWD and create a new empty asp.net website. You don’t need to actually create any files since this site will only be used for debugging. So click the green arrow in the top toolbar to begin debugging. Confirm the prompt and it should open IE and throw a 404 error because you have no files for your empty website. But now you can simply navigate to the site you wish to debug. If any javascript errors are thrown on the page they will translate into the VWD debugger. Here you can now add break points and watches. Refresh the page and begin stepping through the script.

Oracle SQL Developer Error: Exception firing addinsLoaded to oracle.jdevimpl.vcs

Monday, September 27th, 2010

I recently installed a new version the Oracle SQL Developer on my Windows machine and promptly received the following error upon opening the program: ‘SEVERE 46 0 oracle.ide.IdeCore Exception firing addinsLoaded to oracle.jdevimpl.vcs’.

After spending some time trying to determine the source of the problem I decided to read the instruction manual. While I should have read this first to avoid any issues, I figure better late than never. The docs clearly state: ‘… and do not unzip a kit over the SQL Developer files that are included with Oracle Database’. This is of course exactly what I had done.

I promptly cleaned up the old directory and unzipped the new files into a different directory, and sure enough problem solved.

Lessons Learned:

  1. Always read the installation manual before performing installation, duh!
  2. Do not unzip the SQL Developer files on top of an existing set of SQL Developer files.  It won’t work.

Cflayout first tab does not show content bug

Monday, March 29th, 2010

Another issue I ran into when converting some older Coldfusion 8 applications over to a Coldfusion 9 server concerning tabs using the tag. Unlike getDataSource() this issue is a Coldfusion 9 bug. The issue is that if you create a tab layout the first tab does not have an auto-height property. That being said, no matter how much content you put inside the region it will never expand to show the content.

MrTee posted on the Coldfusion 9 docs both the problem and the solution. This is not my solution, I’m just spreading the word here. The link to his comment is here. He has also posted the correct javascript file here.

The problem needs to be corrected in the layout.js file. If you are in your wwwroot folder look under CFIDE/scripts/ajax/package directory. Once you have this file open you can make the changes as expressed by MrTee himself.

The change I made is on line 70 and changed from

var _70=new Ext.Panel({title:_6a,contentEl:_68,_cf_body:_68,id:_69,closable:_6c,tabTip:_6b, autoScroll:_6f,autoShow:true});

to

var _70=new Ext.Panel({title:_6a,contentEl:_68,_cf_body:_68,id:_69,closable:_6c,tabTip:_6b, autoScroll:_6f,autoShow:true,autoHeight:true});

I hope this helps anyone with the same problem out.

All in all an ‘autoHeight:true’ needs added to the Panel() method. As far as I know this has not been addressed in an update by Adobe, but has been acknowledged. I used this solution and it worked perfect with no known side-effects on my own applications.

MySQL Workbench doesn’t have Query Browser or Administrator in 5.1

Friday, March 19th, 2010

If you’re lazy like me and prefer to work in the mysql Administrator and Query Browser as opposed to the command prompt, you may be surprised if you go to the website now to download the GUI tools.  They have changed now to a single application called the Workbench.  This is great and a welcome change in my opinion.  The only problem I found was that they have removed the old GUI tools from the downloads page and have replaced it with the current stable release (5.1) of the Workbench.  This is fine except that the current stable release only contains the new data visualizer.  If you want the Workbench that contains the data visualizer and the Query Browser and Administrator you need to download the beta 5.2.  Unfortunately the beta is not readily available under the downloads page of the main site.  As such, the link to the download at the time of this writing is http://dev.mysql.com/downloads/workbench/.  So if you need the Query Browser and the Administrator you’ll need to download this version, or a later version depending on what is available at the time of your reading.