Forum Stats

  • 3,770,464 Users
  • 2,253,118 Discussions
  • 7,875,466 Comments

Discussions

USER INPUT IN WEB.PY NOT WORKING

limor
limor Member Posts: 38
edited Sep 20, 2016 10:53AM in Python

Hi,

I have a webservice (web.py + cx_Oracle) which needs the user input data.

1.) First I define a web object

data=web.input()

2.) add value to a list

a = [data.ID]

3.) create query

query = "SELECT ... FROM... WHERE a.id = %s;"

Until here it works. But the nex step is to execute the query:

cursor.execute(query, a)

This step will produce an error message. In my case:

'ascii' codec can't decode byte 0xfc in position 36: ordinal not in range(128)

If I define the user input id directly into the sql statement it works fine... does anyone know this kind of issue?

Best Answer

  • limor
    limor Member Posts: 38
    edited Sep 20, 2016 10:53AM Accepted Answer

    I know what was wrong. I should not use %s for the data. Apparently, cx_Oracle defaults to a "named" paramstyle .

    data = web.input(ID='')

    query = "SELECT ... FROM... WHERE a.id =:grid_id "

    cursor.execute(query, {'grid_id':data.ID})

Answers

  • limor
    limor Member Posts: 38
    edited Sep 20, 2016 10:53AM Accepted Answer

    I know what was wrong. I should not use %s for the data. Apparently, cx_Oracle defaults to a "named" paramstyle .

    data = web.input(ID='')

    query = "SELECT ... FROM... WHERE a.id =:grid_id "

    cursor.execute(query, {'grid_id':data.ID})

This discussion has been closed.