[web2py] PyDAL+MSSQL+FreeTDS: pyodbc.ProgrammingError

2019-09-27 Thread Wei Wang
I'm getting the error from a short pytest script:
>
> E   pyodbc.ProgrammingError: ('42000', '[42000] [FreeTDS][SQL 
>> Server]Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS 
>> options to be set for the connection. This ensures consistent query 
>> semantics. Enable these options and then reissue your query. (7405) 
>> (SQLExecDirectW)')
>
>   
>> 
>>   
>>  /usr/local/lib/python3.6/dist-packages/pydal/adapters/base.py:412: 
>> ProgrammingError
>
> PyDAL shows the SQL command is:
command = "SELECT NacConnectionsView.eventdate, 
NacConnectionsView.nacmacaddress, NacConnectionsView.nacswitch FROM 
NacConnectionsView WHERE (NacConnectionsView.nacmacaddress LIKE '00%' 
ESCAPE '\\');"

Where did that [ESCAPE '\\'] part came from?

Thank you for any help!

--Wei Wang

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/a4869e37-c631-4621-85be-e4d900de8da8%40googlegroups.com.


[web2py] SAML2 Service Provider app in web2py?

2014-08-21 Thread Wei Wang
I have the need to use a SAML2 identity provider (specifically, a NetIQ 
product) for authentication and authorization in some web2py apps.

I searched in this group, also googled "web2py and SAML", but did not find 
anything that seems readily available.

My thoughts on building a "Service Provider" (in SAML2 terminology) app in 
web2py alongside other apps:

   - The SAML2 service provider would be "/saml2sp":
  - The saml2sp app communicates to the SAML2 Id provider for 
  authentication and authorization;
  - A web2py app is configured to use "cas_auth", with 
   "localhost/saml2sp" as the CAS server base URL;

Does something like this exist? Does that sound reasonable?

Thanks for any pointers, comments, thoughts.

Wei

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] /default/user/login not honoring "_next" anymore?

2014-06-23 Thread Wei Wang
In the current head branch in github (Version 
2.9.5-trunk+timestamp.2014.06.19.17.16.40), it seems that the 
/default/user/login form does not use the "_next" variable specified in the 
URL.

For example,

The myapp/default/view is decorated with @auth.requires_login(), so when I 
am not logged in, it triggers web2py's login form with this URL:


https://server-name:4443/myapp/default/user/login?_next=/myapp/default/view%3Fapp%3Dnextapp

However, the variable "_next" in the form is always:



I would expect it to be:



Is this a potential bug or is this an expected change?

Thanks,
-- 
Wei Wang

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: An easy way to change "action" in user login form?

2014-02-13 Thread Wei Wang
I gave it a quick and dirty (hopefully temporary) fix: In the 
controller/default.py, I added three lines in the user() function:

if request.args(0)=='login':
if form['_action'] == "#":
form['_action'] = '/midash/default/user/login'

Hopefully, this helps eliminating the possibility of the form causing a 
problem.

On Wednesday, February 12, 2014 11:39:59 PM UTC-5, Wei Wang wrote:
>
> My web2py powered app is behind a reverse proxy (namely, NetIQ Access 
> Manager) for single sign-on. User authentication to my app is done through 
> a form-fill to the form that "/default/user/login" renders as redirected by 
> the @auth.require_login() decorator.
>
> Long story short, this setup stopped working a couple of days ago after 
> worked for months. The NetIQ support engineer thinks that the cause of the 
> problem is the fact that the form contains this:
>
> 
>
> Specifically, the *action="#"* part. He believes that it has to be 
> *action="/default/user/login"* despite the fact that "#" is a perfectly 
> legitimate self-pointing URL.
>
> In the spirit of getting over the problem, I am thinking of digging in the 
> code and change the way that "action" is constructed. Before I spend time 
> to do that, does anyone in the group have an easier way?
>
> Thanks in advance for any help.
> -- 
> Wei Wang
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] An easy way to change "action" in user login form?

2014-02-12 Thread Wei Wang
My web2py powered app is behind a reverse proxy (namely, NetIQ Access 
Manager) for single sign-on. User authentication to my app is done through 
a form-fill to the form that "/default/user/login" renders as redirected by 
the @auth.require_login() decorator.

Long story short, this setup stopped working a couple of days ago after 
worked for months. The NetIQ support engineer thinks that the cause of the 
problem is the fact that the form contains this:



Specifically, the *action="#"* part. He believes that it has to be 
*action="/default/user/login"* despite the fact that "#" is a perfectly 
legitimate self-pointing URL.

In the spirit of getting over the problem, I am thinking of digging in the 
code and change the way that "action" is constructed. Before I spend time 
to do that, does anyone in the group have an easier way?

Thanks in advance for any help.
-- 
Wei Wang

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] A correction needed in the web2py book

2014-01-23 Thread Wei Wang
Thanks. I didn't know the book is in Github.

I forked it and edited the file, which is here: 
g...@github.com:ww9rivers/web2py-book.git

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] How to reverse proxy with web2py?

2014-01-23 Thread Wei Wang
Hi,

I am writing a web2py application, that pulls HTML output from another web 
app (specifically, Splunk web, if anyone cares).

Here is the function that I have arrived at the moment:

import requests as http

def splunk():
kwargs = dict(verify=False)
svc = request.get_vars.get('service')

sess = session.proxy_session
sessid = sess.cookies.get('session_id_8001')
logger.debug('midash/proxy/splunk: Session = %s'%(format(sess)))
if sess is None:
sess = http.Session()
logger.debug('midash/proxy/splunk: Initial contact')
resp = sess.get('https://localhost:8001/', **kwargs)
resp = splunk_auth(sess, **kwargs)

url = 'https://localhost:8001'+(request.vars._url or '')
resp = sess.get(url, **kwargs)
if (sessid != resp.cookies.get('session_id_8001')):
resp = splunk_auth(sess, app=url, **kwargs)
logger.debug('midash/proxy/splunk: url = "%s" %s)'%(url, format(resp)))
for hkey,hval in resp.headers.iteritems():
logger.debug('midash/proxy/splunk: header[%s] = %s'%(hkey, hval))

session.proxy_session = sess
for hkey in [ 'conten-type' ]:
hval = resp.headers.get(hkey)
if hval:
response.headers[hkey] = hval
return response.stream(resp.raw)

def splunk_auth(sess, app='%2Fen-US%2F', **kwargs):
cval = sess.cookies.get('cval')
uagent = request.env.user_agent
if uagent:
sess.headers['User-Agent'] = uagent
logger.debug('midash/proxy/splunk_auth: cval = %s, app=%s'%(cval, app))
return sess.post(
'https://localhost:8001/en-US/account/login?return_to=%s'%(app),
 data = dict(username='admin', password='changeme',cval 
= cval),
 **kwargs)


For debugging purpose, I made a small wrapper class to wrap "resp.raw" 
which is a urllib3.HTTPResponse object. In debug logging, I can see that I 
get the contents I expected from https://localhost:8001/. However, in the 
browser, the call going to the above splunk function would get a status 200 
with 0-byte content (debug logging shows header[content-length] = 14372.)

Is return response.stream() the right way for this?

Thanks!

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] A correction needed in the web2py book

2014-01-23 Thread Wei Wang
Hi,

There is an error in this section of the Reference Manual book:

http://web2py.com/books/default/chapter/29/04/the-core#response

Specifically, this:

response.stream(file, chunk_size, request=request, attachment=False, 
filename=None, headers=None)

does not match the function signature in the current source code, which 
does not take a headers parameter.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Simple BASE in routes.py gives me "invalid request"

2013-08-29 Thread Wei Wang
Jonathan,

I am embarrassed to report that is has been a user error -- my fault -- 
that I got two different versions of web2py running in the same instance of 
apache2. I didn't think to check my Apache configuration until I downloaded 
a stable version of the source, set it up and ran it manually, then the 
problem went away.

Your attention and support has been wonderful and much appreciated.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Simple BASE in routes.py gives me "invalid request"

2013-08-28 Thread Wei Wang
Just got a chance to try this: I copied the 
"midash/views/default/user.html" to"miops/views/default/user.html", 
reloaded the page at "/midash/user/login?_next=/midash/default/index", my 
user login page shows up.

So I guess there is a bug somewhere in the routing code.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Simple BASE in routes.py gives me "invalid request"

2013-08-27 Thread Wei Wang
"/midash/xyz/abc" gives me "invalid function (default/xyz)".

"/midash/default/abcdefg" gives me "invalid function (default/abcdefg)".

I just tried with a copy of the "user" function from 
"midash/controllers/default.py" to "miops/controllers/default.py". That 
gives me an error message that may be telling:

invalid view (default/user.html)
That seems to mean that the URI "/midash/default/user/login?_next=/midash" 
somehow got routed to "/miops/default/user/login" -- The reason for my 
suspicion is that I do have a "midash/views/default/user.html" but no 
"user.html" anywhere in "miops".

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Simple BASE in routes.py gives me "invalid request"

2013-08-27 Thread Wei Wang
VERSION = Version 2.6.0-development+timestamp.2013.08.15.10.05.27

On Tuesday, August 27, 2013 2:04:54 PM UTC-4, Jonathan Lundell wrote:
>
> On 27 Aug 2013, at 10:38 AM, Wei Wang > 
> wrote:
>
> On Tuesday, August 27, 2013 12:54:51 PM UTC-4, Jonathan Lundell wrote:
>>
>> On 27 Aug 2013, at 9:47 AM, Wei Wang  wrote:
>>
>> I have 2 simple apps: midash and miops. I intend to require user 
>> authentication for accessing "midash" and not "miops".
>>
>> In "miops/controllers/default.py" I have only an "index()" function, 
>> while in "midash/controllers/default.py" I do have a "user()" function.
>>
>> A path of "midash/default/user/login?_next=/midash" gives me an "invalid 
>> request" error.
>>
>>
>> Is there more to the error message? 
>>
>
> No. That's all.
>
> I did a "view page source" in Chrome, the entire page is just "
> invalid request".
>
>
>
> What version of web2py are you running?
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Simple BASE in routes.py gives me "invalid request"

2013-08-27 Thread Wei Wang


On Tuesday, August 27, 2013 12:54:51 PM UTC-4, Jonathan Lundell wrote:
>
> On 27 Aug 2013, at 9:47 AM, Wei Wang > 
> wrote:
>
> I have 2 simple apps: midash and miops. I intend to require user 
> authentication for accessing "midash" and not "miops".
>
> In "miops/controllers/default.py" I have only an "index()" function, while 
> in "midash/controllers/default.py" I do have a "user()" function.
>
> A path of "midash/default/user/login?_next=/midash" gives me an "invalid 
> request" error.
>
>
> Is there more to the error message? 
>

No. That's all.

I did a "view page source" in Chrome, the entire page is just "
invalid request".

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Simple BASE in routes.py gives me "invalid request"

2013-08-27 Thread Wei Wang
Here is the entire "routes.py" I have:

routers = dict(
BASE=dict(
default_application='miops',
),
)

logging = 'debug'

if __name__ == '__main__':
import doctest
doctest.testmod()


I am testing the web2py (Version 
2.6.0-development+timestamp.2013.08.15.10.05.27) instance under Apache2 
using mod_python and "modpythonhandler" came with web2py.

I have 2 simple apps: midash and miops. I intend to require user 
authentication for accessing "midash" and not "miops".

In "miops/controllers/default.py" I have only an "index()" function, while 
in "midash/controllers/default.py" I do have a "user()" function.

A path of "midash/default/user/login?_next=/midash" gives me an "invalid 
request" error.

I put some test cases in "routes.py", they seem to work fine:

'''
>>> import sys
>>> import os
>>> path = os.path.dirname(os.path.abspath(__file__))
>>> sys.path = [path] + [p for p in sys.path if not p == path]
>>> os.chdir(path)
>>> import gluon.main
>>> from gluon.rewrite import load, filter_url, filter_err, 
get_effective_router
>>> load(routes=os.path.basename(__file__))
...
>>> filter_url('http://domain.com/')
'/miops/default/index'
>>> filter_url('http://domain.com/miops/apps?app=abc')
'/miops/apps/index ?app=abc'
>>> filter_url('http://domain.com/midash/default/user/login?_next=/midash')
"/midash/default/user ['login'] ?_next=/midash"
'''



Thank you very much for your help.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] A possible bug in modpythonhandler.py?

2012-10-23 Thread Wei Wang
For reasons out of my control, I have to install web2py using mod_python. 
So I configured the following in an apache vhost file:

Alias / /opt/web2py/

SetHandler python-program
PythonHandler modpythonhandler
PythonPath "sys.path+['/opt/web2py']"
#PythonOption SCRIPT_NAME /welcome
PythonDebug On

AllowOverride None
Options -Indexes FollowSymLinks
Order Allow,Deny
Allow from all


I tried a number of combinations of PythonOption SCRIPT_NAME but have not 
been able to get an anything, such as the "welcome" application. Going to / 
on this server redirects me to "welcome/default/index" which then gives me 
an "invalid request" message.

So I found the line in gluon/main.py that generated the "invalid request" 
message and changed it to this:

% ('invalid request, app = %s, request.folder = %s' % (app, 
request.folder)),


Which gives me the application name and the folder. Here is what I get then:

invalid request, app = default, request.folder = 
/opt/netapps/web2py/applications/default/


It seems that something is not parsing the URL right since the URL is:

http:///welcome/default/index


 

-- 





[web2py] Re: Help with db.import_from_csv_file()?

2011-06-19 Thread Wei Wang
OK. :-) Thanks!


[web2py] Re: Help with db.import_from_csv_file()?

2011-06-19 Thread Wei Wang
I think I may have found out why that was happening.

In the latest version of dal.py, lines 4765-4766 read:

elif field.type in ('double','integer'):
value = None

That basically eliminates any data of type double or integer. Commenting 
those two lines and restart web2py seems to work for my import.

Now, why does the Table.import_from_csv_file() method does something like 
that?


[web2py] Help with db.import_from_csv_file()?

2011-06-19 Thread Wei Wang
Greetings!

I have a simple form, which takes in a CSV file name and upload the file for 
import to database.

This is the code to import uploaded data:

if form.accepts(request.vars, session):
response.flash = 'Form accepted'
db.import_from_csv_file(request.vars.csvfile.file)

In the database db, I have a table "unit":

db.define_table('unit',
Field('org', db.org, requires=IS_NOT_EMPTY()),
Field('type', type='integer', label=T('Unit Type'), 
requires=IS_NOT_EMPTY(),),
Field('name', type='string', label=T('Unit Name'), 
requires=IS_NOT_EMPTY(),))

The problem is: When I upload the file below, I get all NULL's for the 
unit.type field.

TABLE unit
unit.org,unit.type,unit.name
1,1,"Unit 10"
1,1,"Unit 12"
1,1,"Unit 13"
1,1,"Unit 14"
1,1,"Unit 15"
1,1,"Unit 16"
1,1,"Unit 17"
1,1,"Unit 18"
1,1,"Unit 7"
1,1,"Unit 8"
1,1,"Unit 9"
1,2,"Unit 10"
1,2,"Unit 19"
1,3,"Unit 13"
1,3,"Unit 14"
1,3,"Unit 15"
1,3,"Unit 17"
1,3,"Unit 18"
1,3,"Unit 19"
1,3,"Unit 4"
1,3,"Unit 6"
1,3,"Unit 8"
1,3,"Unit 9"
2,1,"Unit 22"
2,1,"Unit 23"
2,2,"Unit 20"
2,3,"Unit 21"
3,1,"Unit 32"
3,1,"Unit 34"
3,3,"Unit 31"
3,3,"Unit 33"
4,1,"Unit 37"
4,1,"Unit 42"
4,2,"Unit 39"
4,2,"Unit 44"
4,2,"Unit 47"
4,3,"Unit 45"
4,3,"Unit 48"

END

Help is much appreciated.