8 Replies - 881 Views - Last Post: 15 January 2013 - 08:32 AM Rate Topic: -----

#1 theNoob  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 66
  • Joined: 14-July 12

TypeError: cannot concatenate 'str' and 'NoneType' obj

Posted 15 January 2013 - 04:57 AM

Hi Guys,

I am currently working with the web2py frame work and creating a similar website as to www.webjet.com.au (its just a uni project).

One of the function I need to write is the searchFlights function where I have created a custom HTML form which allows users to select dates, location etc etc.. The HTML is meant to send this information back to the function defined in the controller... where it then queries the database and returns the flight results...

The code for querying the database is:

def show():
    receivedFlights = request.vars.DepartureLocation+','+request.vars.ArrivalLocation+','+request.vars.type+','+request.vars.DepartureDate+','+request.vars.ArrivalDate+','+request.vars.classType+','+request.vars.noOfAdults+','+request.vars.noOfChildren+','+request.vars.noOfInfants
    return dict(txt1=recievedflights, flights=db().select(db.Flight.request.DepartureLocation+','+request.vars.ArrivalLocation+','+request.vars.type+','+request.vars.DepartureDate+','+request.vars.ArrivalDate+','+request.vars.classType+','+request.vars.noOfAdults+','+request.vars.noOfChildren+','+request.vars.noOfInfants))



I am currently getting an error when i try to search the flights... error is:
cannot concatenate 'str' and 'NoneType' objects

Is This A Good Question/Topic? 0
  • +

Replies To: TypeError: cannot concatenate 'str' and 'NoneType' obj

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2153
  • View blog
  • Posts: 3,311
  • Joined: 21-June 11

Re: TypeError: cannot concatenate 'str' and 'NoneType' obj

Posted 15 January 2013 - 05:16 AM

The error message is telling you that (at least) one of the members you're trying to concatenate is None.

This post has been edited by sepp2k: 15 January 2013 - 05:16 AM

Was This Post Helpful? 0
  • +
  • -

#3 theNoob  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 66
  • Joined: 14-July 12

Re: TypeError: cannot concatenate 'str' and 'NoneType' obj

Posted 15 January 2013 - 05:20 AM

Hi sepp2k,

I have gone through all my code, there is no object in the code that is set to none.. There was a drop drop menu in my HTML code where the first option was set to blank, which I commented out however still getting the same error message...

I've pasted my code below... can't seem to find whats set to none?

{{extend 'layout.html'}}
<html>

<h2>Search Flights </h2> </br>

<form action="show" enctype="multipart/form-data" method="post">
    <table>
    <tr>
        <td>
            <label> Origin City: </label>
        </td>
        <td>
            <select name="DepartureLocation">
                <!--<option value="blank"></option>-->
                <option value="Adelaide">Adelaide</option>
                <option value="Brisbane">Brisbane</option>
                <option value="Cairns">Cairns</option>
                <option value="Canberra">Canberra</option>
                <option value="Darwin">Darwin</option>
                <option value="Goldcoast">Goldcoast</option>
                <option value="Hobart">Hobart</option>
                <option value="Mackay">Mackay</option>
                <option value="Newcastle">Newcastle</option>
                <option value="Perth">Perth</option>
                <option value="Rockhampton">Rockhampton</option>
                <option value="SunshineCoast">Sunshine Coast</option>
                <option value="Sydney">Sydney</option>
                <option value="Townsville">Townsville</option>
            </select>
        </td>

        <td>
            <label> Destination City: </label>
        </td>
        <td>
            <select name="ArrivalLocation">
               <!--<option value="blank"></option>-->
                <option value="Adelaide">Adelaide</option>
                <option value="Brisbane">Brisbane</option>
                <option value="Cairns">Cairns</option>
                <option value="Canberra">Canberra</option>
                <option value="Darwin">Darwin</option>
                <option value="Goldcoast">Goldcoast</option>
                <option value="Hobart">Hobart</option>
                <option value="Mackay">Mackay</option>
                <option value="Newcastle">Newcastle</option>
                <option value="Perth">Perth</option>
                <option value="Rockhampton">Rockhampton</option>
                <option value="SunshineCoast">Sunshine Coast</option>
                <option value="Sydney">Sydney</option>
                <option value="Townsville">Townsville</option>
            </select>
        </td>
        <td>
        </td>   
    </tr>
    
    <td></td>
    <td></td>
    
    <tr>
        <td>
            <label> Type: </label>
        </td>
        <td>
            <input type="radio" name="type" value="oneWay"> One Way
            <input type="radio" name="type" value="return"> Return
        </td>
        <td>
        </td>
    </tr>
    
    <td></td>
    <td></td>
    
    <tr>
        <td>
            <label> Departure Date:  </label>
        </td>
        
        <td>
            <input type="text" name="DepartureDate">
        </td>
        
        <td>
        </td>
    </tr>
    
    <td></td>
    <td></td>
    
    <tr>
        <td>
            <label> Arrival Date: </label>
        </td>
        
        <td>
            <input type="text" name="ArrivalDate">
        </td>
    </tr>
    
    <td></td>
    <td></td>
    
    <tr>
        <td>
            <label> Class: </label>
        </td>
        
        <td>
            <select name="classType">
                <option value="firstClass">First Class</option>
                <option value="busClass">Business Class</option>
                <option value="ecoClass">Economy Class</option>
            </select>
        </td>
    </tr>
    
    <td></td>
    <td></td>
    
    <tr>
        <td>
            <label> Adults: </label>
        </td>
        <td>
            <select name="noOfAdults">
                <option value="ad1">1</option>
                <option value="ad2">2</option>
                <option value="ad3">3</option>
                <option value="ad4">4</option>
                <option value="ad5">5</option>
            </select>
        
        <td>
            <label> Children (2-11 yrs): </label>
        </td>
        <td>
             <select name="noOfChildren">
                <option value="chd0">0</option>
                <option value="chd1">1</option>
                <option value="chd2">2</option>
                <option value="chd3">3</option>
                <option value="chd4">4</option>
                <option value="chd5">5</option>
            </select>
        <td>
        
        <td>
            <label> Infants (<2 yrs): </label>
        </td>
        <td>
            <select name="noOfInfants">
                <option value="inf0">0</option>
                <option value="inf1">1</option>
                <option value="inf2">2</option>
                <option value="inf3">3</option>
                <option value="inf4">4</option>
                <option value="inf5">5</option>
            </select>  
        <td>
    </tr>
    
    <tr>
        <td>
            <input type ="submit" value="submit">       
        </td>
    </tr>
    
</table>
        
</form>



Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2153
  • View blog
  • Posts: 3,311
  • Joined: 21-June 11

Re: TypeError: cannot concatenate 'str' and 'NoneType' obj

Posted 15 January 2013 - 05:36 AM

Modify your method so that the first thing it does is to print the repr of all the members you're going to use (or just print for each one whether it's equal to None). One of them has to be None - error messages don't lie.

If you're comfortable using a debugger, you can also use that instead of adding print statements.

This post has been edited by sepp2k: 15 January 2013 - 06:21 AM
Reason for edit:: repr, not __repr__

Was This Post Helpful? 0
  • +
  • -

#5 theNoob  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 66
  • Joined: 14-July 12

Re: TypeError: cannot concatenate 'str' and 'NoneType' obj

Posted 15 January 2013 - 05:44 AM

Hi sepp2k,

I haven't actually used a debugger before and I don't understand how __repr__ works or how to actually implement it..

This post has been edited by theNoob: 15 January 2013 - 05:46 AM

Was This Post Helpful? 0
  • +
  • -

#6 theNoob  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 66
  • Joined: 14-July 12

Re: TypeError: cannot concatenate 'str' and 'NoneType' obj

Posted 15 January 2013 - 06:14 AM

Hi sepp2k,

I figured out what the issue was. I was submitted the form without entering any dates into the datefrom and dateto location.. hence it game me an error. i am still getting another error but trying to work on it right now..
Was This Post Helpful? 0
  • +
  • -

#7 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2153
  • View blog
  • Posts: 3,311
  • Joined: 21-June 11

Re: TypeError: cannot concatenate 'str' and 'NoneType' obj

Posted 15 January 2013 - 06:25 AM

View PosttheNoob, on 15 January 2013 - 01:44 PM, said:

I haven't actually used a debugger before and I don't understand how __repr__ works or how to actually implement it..


Actually, you could have just printed the values without repr. I was under the impression that print won't print anything if the argument is None, but that's not actually true.

Anyway repr works by simply wrapping a value with repr( ) when printing it (i.e. print(repr(my_value))). This often produces output that's more suitable for debugging than just printing it normally.
Was This Post Helpful? 0
  • +
  • -

#8 theNoob  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 66
  • Joined: 14-July 12

Re: TypeError: cannot concatenate 'str' and 'NoneType' obj

Posted 15 January 2013 - 06:31 AM

Sweet thank you. That is very helpful.

I am currently working with the datepicker for the arrival date where it would automatically pop up the calendar for the user to input the date.
The calendar pops up for the departure date but it doesn't do it for the arrival date.

I was wondering if you could have see what I maybe doing wrong?


<head>
    <meta charset="utf-8" />
        <title> Search Flights </title>
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
        <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
        <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
        <script>
        $(function() {
        $( "#datepicker" ).datepicker();
        });
        </script>
</head>



...
code...
...
<input type="text" name="DepartureDate" id="datepicker">
...
code...
...

...
code...
...
<input type="text" name="ArrivalDate" id="datepicker">
...
code...
...




Not sure why it isn't working..
Was This Post Helpful? 0
  • +
  • -

#9 theNoob  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 66
  • Joined: 14-July 12

Re: TypeError: cannot concatenate 'str' and 'NoneType' obj

Posted 15 January 2013 - 08:32 AM

Hi sepp2k,

I am still working with the code and currently getting another errors... its just getting worst with time :(

its the same function as above to search flights... however the error is different:

Error traceback:
Traceback (most recent call last):
File "I:\wdd-softw\web2py\gluon\restricted.py", line 184, in restricted
File "K:/wdd-softw/web2py/applications/Assignment/controllers/default.py", line 109, in <module>
File "I:\wdd-softw\web2py\gluon\globals.py", line 103, in <lambda>
File "K:/wdd-softw/web2py/applications/Assignment/controllers/default.py", line 106, in show
receivedFlights = request.vars.DepartureLocation+','+request.vars.ArrivalLocation+','+request.vars.type+','+request.vars.DepartureDate+','+request.vars.ArrivalDate+','+request.vars.classType+','+request.vars.noOfAdults+','+request.vars.noOfChildren+','+request.vars.noOfInfants
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1