[web2py] Re: Best way to access files outside of static

2013-12-12 Thread AbrahamLinksys
For a compelling (and humorous) argument of why NOT to use Regex to parse 
XML/HTML, read this SO nugget:

http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags

Seriously, it's my favorite SO post ever. Enjoy!

On Wednesday, December 11, 2013 8:47:42 PM UTC-6, Cliff wrote:

 That was very helpful. I can now hear music! The regex so far has just 
 been working so I haven't messed with it. Thanks for the suggestion, I will 
 look into better ways to manage the XML.

 Thanks Leonel!

 On Wednesday, December 11, 2013 7:08:11 PM UTC-5, Leonel Câmara wrote:

 Heres an example

 def stream():
 
 Stream an mp3 from an absolute path given as var
 WARNING: This is definitely unsafe as it doesn't care what that path 
 is at all.
 WARNING: Seriously this is just an example, don't use it.
 
 import os
 if os.path.exists(request.vars.path):
 response.headers['Content-Type'] = 'audio/mpeg3'
 return response.stream(open(request.vars.path, 'rb'), 
 chunk_size=4096)
 else:
 raise HTTP(404)


 By the way, after looking at your code, I have to say, you really 
 shouldn't use regexes to parse XML, it's really not their purpose. It's 
 quite simple to refactor that using cElementTree or any other xml parser.

 Good luck with your project!

 Quarta-feira, 11 de Dezembro de 2013 0:11:46 UTC, Cliff escreveu:

 Hello.

 I am new to both python and web2py but have been playing with it a bit. 
 I have made a simple program to listen to like artists from lastfm's API. I 
 store my mp3s in a database: Artist/Track/File. It will go through my mp3s 
 and find like songs and play them with jPlayer. I am stuck at playing the 
 songs with jPlayer. It is trying to play my songs from 
 /media/Music/artist/track.mp3 which is out of web2py's static dir. What 
 would be the best way to allow web2py to access these files? If you had any 
 examples that would be great.

 An example of the error: HTTP load failed with status 404. Load of media 
 resource https://IP:8080/media/Music/mp3/Artist/Song.mp3 failed. 
  (removed IP and artist/song since they were not important)

 This will only be used by me and on my local server so I am not 
 concerned with the security issues of accessing files outside of static.


 Thanks!

 Cliff



-- 
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] Re: Internal Error - Ticket unknown - only over HTTPS?!

2013-11-01 Thread AbrahamLinksys
Hi Michele,

Thanks for your response. I actually managed to solve it.

To review, thanks for the idea of looking at tickets -- unfortunately, part 
of the issue was that tickets were not being written for these errors, thus 
there is nothing to unpickle :(

So, since the app was not generating errors when running over WSGI with 
HTTP, so I THOUGHT that the error WAS at the web2py or wsgi level.

But when I started logging things (good suggestion by the way; I'd never 
really had luck with web2py logging, but I finally figured it out!) 
I found my models weren't loading past the auth define tables call. Turns 
out some sort of migration was trying to happen, as setting migrate=False 
in auth.define_tables() call fixed that, even though I had fake_migrate_all 
set in the DAL definition (it didn't seem to care... probably it was a 
permissions issue on the databases folder, but I copied metadata files from 
the dev server and that seemed to fix it).

But I still had other issues related to my login pages and most pages with 
DB access and some forms using session, still only over https.  Anyway, 
after the unkown ticket issue went away, these pages would generate an 
unrecoverable ticket error (still not writing any ticket). 

After stumbling around on this list, i found someone who had seen many 
people have the unrecoverable ticket, but that his problem and solution was 
generally different than theirs -- he had a permissions issue. I had 
already verified the web user was running web2py and had proper 
permissions, but I did a chmod 777 on the sessions directory anyway (that 
means fully open permissions fyi) and voila!

That solved all my issues! Because of the way I had configured mod_wsgi, 
the HTTPS instances were running under the user apache (as defined by 
default in httpd.conf), whereas the HTTP instances were running as the 
web user because they had a WSGIProcess

It didn't seem to like me adding WSGIProcessGroup web2py to the SSL 
VirtualHost sections, so I defined a separate processgroup for the SSL 
instances . Maybe the thing to do is to put the original WSGIDaemonProcess 
declaration outside all the Vhosts and use the same web2py process group 
for all VHosts, but it's working this way, so this is the way it shall 
work. 

Anyway, this eliminated all the permissions errors because now it's running 
properly as the web user over SSL and can function as intended. 

So the new apache config file for SSL looks like this (changes in 
bold/italic):

VirtualHost *:80
...
WSGIDaemonProcess web2py user=web-user group=web-user threads=15 
display-name=%{GROUP}
WSGIDaemonProcess web2py
...
/VirtualHost


LoadModule ssl_module modules/mod_ssl.so

*WSGIDaemonProcess web2py-ssl user=web-user group=web-user threads=15 
display-name=%{GROUP}*

Listen 443
NameVirtualHost *:443
VirtualHost *:443
 ServerName app1.domain.edu

  SSLEngine on
 SSLCertificateFile /etc/pki/tls/certs/app1.domain.edu.crt
 SSLCertificateKeyFile /etc/ssl/private/server.private.key

  Location /admin
   Deny from all
 /Location

  *WSGIProcessGroup web2py-ssl*
  WSGIScriptAlias / /var/www/web2py/wsgihandler.py

  Alias /css/ /var/www/web2py/applications/app1/static/
 AliasMatch ^/([^/]+)/static/(.*) \
  /var/www/web2py/applications/$1/static/$2
 Directory /var/www/web2py/applications/*/static/*/
   Order Allow,Deny
   Allow from all
 /Directory
VirtualHost

VirtualHost *:443
 ServerName app2.domain.edu

  SSLEngine on
 SSLCertificateFile /etc/pki/tls/certs/app2.domain.edu.crt
 SSLCertificateKeyFile /etc/ssl/private/server.private.key

  Location /admin
   Deny from all
 /Location

*  WSGIProcessGroup web2py-ssl*
  WSGIScriptAlias / /var/www/web2py/wsgihandler.py

  Alias /css/ /var/www/web2py/applications/app2/static/
 AliasMatch ^/([^/]+)/static/(.*) \
  /var/www/web2py/applications/$1/static/$2
 Directory /var/www/web2py/applications/*/static/*/
   Order Allow,Deny
   Allow from all
 /Directory
VirtualHost


And now the permissions aren't an issue and we don't have any 
login/sessions/forms issues. 

:D 









import logging
logger = logging.getLogger(web2py.app.app2)
logger.setLevel(logging.DEBUG)


logger.info(HERE)

On Wednesday, October 30, 2013 12:49:28 PM UTC-5, AbrahamLinksys wrote:

 Hi all,

 I'm running a little older version of web2py in production (1.99.7). 

 I have two apps configured to different subdomains --
 app1.domain.edu - app1
 app2.domain.edu - app2

 This works fine. Great in fact -- I'm using routers to make the apps 
 default based on the domain, so appnames aren't needed. 

 Recently we decided to add authenticated services to the applications, so 
 I got some certificates and set up web2py over SSL.

 So over https, app1 works fine but app2 generates the unknown ticket 
 issue. 

 This doesn't appear to be any sort of permissions or storage issue (lots 
 of room/inodes on disk, errors dir writable by app2 when requested over 
 HTTP -- doesn't normally generate an error over HTTP, I

[web2py] Re: Internal Error - Ticket unknown - only over HTTPS?!

2013-11-01 Thread AbrahamLinksys
Also -- I'm pretty sure all the tickets turned to unknown/unrecoverable 
because the errors directory was also unwritable, hence the inability to 
see the actual error messages (which probably referred to the database most 
of the time... )

So a good way to check for that early on when receiving strange errors like 
that is to chmod the errors directory:

chmod 777 /path/to/web2py/applications/app/errors

But probably best not to leave it that way. 

On Friday, November 1, 2013 3:44:30 PM UTC-5, AbrahamLinksys wrote:

 Hi Michele,

 Thanks for your response. I actually managed to solve it.

 To review, thanks for the idea of looking at tickets -- unfortunately, 
 part of the issue was that tickets were not being written for these errors, 
 thus there is nothing to unpickle :(

 So, since the app was not generating errors when running over WSGI with 
 HTTP, so I THOUGHT that the error WAS at the web2py or wsgi level.

 But when I started logging things (good suggestion by the way; I'd never 
 really had luck with web2py logging, but I finally figured it out!) 
 I found my models weren't loading past the auth define tables call. Turns 
 out some sort of migration was trying to happen, as setting migrate=False 
 in auth.define_tables() call fixed that, even though I had fake_migrate_all 
 set in the DAL definition (it didn't seem to care... probably it was a 
 permissions issue on the databases folder, but I copied metadata files from 
 the dev server and that seemed to fix it).

 But I still had other issues related to my login pages and most pages with 
 DB access and some forms using session, still only over https.  Anyway, 
 after the unkown ticket issue went away, these pages would generate an 
 unrecoverable ticket error (still not writing any ticket). 

 After stumbling around on this list, i found someone who had seen many 
 people have the unrecoverable ticket, but that his problem and solution was 
 generally different than theirs -- he had a permissions issue. I had 
 already verified the web user was running web2py and had proper 
 permissions, but I did a chmod 777 on the sessions directory anyway (that 
 means fully open permissions fyi) and voila!

 That solved all my issues! Because of the way I had configured mod_wsgi, 
 the HTTPS instances were running under the user apache (as defined by 
 default in httpd.conf), whereas the HTTP instances were running as the 
 web user because they had a WSGIProcess

 It didn't seem to like me adding WSGIProcessGroup web2py to the SSL 
 VirtualHost sections, so I defined a separate processgroup for the SSL 
 instances . Maybe the thing to do is to put the original WSGIDaemonProcess 
 declaration outside all the Vhosts and use the same web2py process group 
 for all VHosts, but it's working this way, so this is the way it shall 
 work. 

 Anyway, this eliminated all the permissions errors because now it's 
 running properly as the web user over SSL and can function as intended. 

 So the new apache config file for SSL looks like this (changes in 
 bold/italic):

 VirtualHost *:80
 ...
 WSGIDaemonProcess web2py user=web-user group=web-user threads=15 
 display-name=%{GROUP}
 WSGIDaemonProcess web2py
 ...
 /VirtualHost


 LoadModule ssl_module modules/mod_ssl.so

 *WSGIDaemonProcess web2py-ssl user=web-user group=web-user threads=15 
 display-name=%{GROUP}*

 Listen 443
 NameVirtualHost *:443
 VirtualHost *:443
  ServerName app1.domain.edu

   SSLEngine on
  SSLCertificateFile /etc/pki/tls/certs/app1.domain.edu.crt
  SSLCertificateKeyFile /etc/ssl/private/server.private.key

   Location /admin
Deny from all
  /Location

   *WSGIProcessGroup web2py-ssl*
   WSGIScriptAlias / /var/www/web2py/wsgihandler.py

   Alias /css/ /var/www/web2py/applications/app1/static/
  AliasMatch ^/([^/]+)/static/(.*) \
   /var/www/web2py/applications/$1/static/$2
  Directory /var/www/web2py/applications/*/static/*/
Order Allow,Deny
Allow from all
  /Directory
 VirtualHost

 VirtualHost *:443
  ServerName app2.domain.edu

   SSLEngine on
  SSLCertificateFile /etc/pki/tls/certs/app2.domain.edu.crt
  SSLCertificateKeyFile /etc/ssl/private/server.private.key

   Location /admin
Deny from all
  /Location

 *  WSGIProcessGroup web2py-ssl*
   WSGIScriptAlias / /var/www/web2py/wsgihandler.py

   Alias /css/ /var/www/web2py/applications/app2/static/
  AliasMatch ^/([^/]+)/static/(.*) \
   /var/www/web2py/applications/$1/static/$2
  Directory /var/www/web2py/applications/*/static/*/
Order Allow,Deny
Allow from all
  /Directory
 VirtualHost


 And now the permissions aren't an issue and we don't have any 
 login/sessions/forms issues. 

 :D 









 import logging
 logger = logging.getLogger(web2py.app.app2)
 logger.setLevel(logging.DEBUG)


 logger.info(HERE)

 On Wednesday, October 30, 2013 12:49:28 PM UTC-5, AbrahamLinksys wrote:

 Hi all,

 I'm running a little older version of web2py in production (1.99.7). 

 I have two apps configured

[web2py] Internal Error - Ticket unknown - only over HTTPS?!

2013-10-30 Thread AbrahamLinksys
Hi all,

I'm running a little older version of web2py in production (1.99.7). 

I have two apps configured to different subdomains --
app1.domain.edu - app1
app2.domain.edu - app2

This works fine. Great in fact -- I'm using routers to make the apps 
default based on the domain, so appnames aren't needed. 

Recently we decided to add authenticated services to the applications, so I 
got some certificates and set up web2py over SSL.

So over https, app1 works fine but app2 generates the unknown ticket issue. 

This doesn't appear to be any sort of permissions or storage issue (lots of 
room/inodes on disk, errors dir writable by app2 when requested over HTTP 
-- doesn't normally generate an error over HTTP, I could 777 the errors dir 
but I can't see how that would be an issue).

Also, on the test server (where I run rocket) both sites run fine over 
HTTPS, albeit with cert warnings because of my self-signed test certs. 
There I have an two web2py daemons -- one for HTTP and one for HTTPS 
running on two different ports, using apache with mod_proxy to dispatch 
requests based on the hostname. 


Does anyone have any ideas? I'm thinking it's might be related to the 
routers feature ... or maybe somehow app1's directories or models are 
getting loaded when requesting app2? I'm not even really sure how to 
diagnose the issue as I don't see any logs to read (though I haven't ever 
used web2py's logging, perhaps that would help?)


Also -- and I doubt this is an issue but I'll just throw it out there -- I 
used the same private key to generate CSRs for both SSL certificates for 
the two FQDNs -- is it possible that WSGI doesn't like this? As far as I 
know this is accepted when generating SSL certs. And I don't get any 
certificate issues when using the two domains.. and when just serving HTML 
from the filesystem w/apache everything is fine. 


If I don't make progress I will probably try to upgrade to the newest 
version of web2py and see if the issue persists... however any help is 
appreciated!


Here are some relevant snippets from config files:

/var/www/web2py/routes.py

routers = dict(
  BASE  = dict(
domains = {
  'app1.domain.edu': 'app1',
  'www.app1.domain.edu': 'app1',
  'app2.domain.edu': 'app2',
  'www.app2.domain.edu': 'app2',
  'www.app2.domain.edu:443': 'app2/default' # I added this after 
getting the error, it doesn't seem to affect it. It's not currently in my 
routes file, still getting error. 
}
  ),
)


apache conf:

NameVirtualHost *:80

Directory /var/www/web2py
  AllowOverride None
  Order Allow,Deny
  Deny from all
  Files wsgihandler.py
Allow from all
  /Files
/Directory

WSGISocketPrefix /var/run/wsgi/
Virtualhost *:80
  ServerName app1.domain.edu
  ServerAlias app2.domain.edu

  WSGIDaemonProcess web2py user=webadmin group=webadmin threads=15 \
   display-name=%{GROUP}
  WSGIProcessGroup web2py
  WSGIApplicationGroup %{RESOURCE}

  # This routes all requests that aren't user-dir or awstats requests to 
web2py
  WSGIScriptAliasMatch ^(/([^~].*|awstats.*)?)$ 
/var/www/web2py/wsgihandler.py$1

  # ... mod_user stuff that I won't bother copying is here (for tilde 
sites) ... #

  Alias /css/ /var/www/web2py/applications/app1/static/

  AliasMatch ^/([^/]+)/static/(.*) \
   /var/www/web2py/applications/$1/static/$2
  Directory /var/www/web2py/applications/*/static/*/
Order Allow,Deny
Allow from all
  /Directory
/VirtualHost



LoadModule ssl_module modules/mod_ssl.so

Listen 443
NameVirtualHost *:443
VirtualHost *:443
  ServerName app1.domain.edu

  SSLEngine on
  SSLCertificateFile /etc/pki/tls/certs/app1.domain.edu.crt
  SSLCertificateKeyFile /etc/ssl/private/server.private.key

  Location /admin
Deny from all
  /Location

  WSGIScriptAlias / /var/www/web2py/wsgihandler.py

  Alias /css/ /var/www/web2py/applications/app1/static/
  AliasMatch ^/([^/]+)/static/(.*) \
   /var/www/web2py/applications/$1/static/$2
  Directory /var/www/web2py/applications/*/static/*/
Order Allow,Deny
Allow from all
  /Directory
VirtualHost

VirtualHost *:443
  ServerName app2.domain.edu

  SSLEngine on
  SSLCertificateFile /etc/pki/tls/certs/app2.domain.edu.crt
  SSLCertificateKeyFile /etc/ssl/private/server.private.key

  Location /admin
Deny from all
  /Location

  WSGIScriptAlias / /var/www/web2py/wsgihandler.py

  Alias /css/ /var/www/web2py/applications/app2/static/
  AliasMatch ^/([^/]+)/static/(.*) \
   /var/www/web2py/applications/$1/static/$2
  Directory /var/www/web2py/applications/*/static/*/
Order Allow,Deny
Allow from all
  /Directory
VirtualHost





-- 
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 

[web2py] Re: Ticket Issued: Unrecoverable

2012-08-01 Thread AbrahamLinksys
Are 100% sure it's not permissions (e.g. you've run chmod recursively on 
the root of your app)?

If so, I've also seen this error when mod_wsgi is misconfigured. In my 
case, I was able to visit one application (which was the default_app set in 
routers.BASE) but visiting the other resulted in the unrecoverable ticket. 
Maybe it was something to do with the applications' contexts becoming 
mixed... I'm really not sure. 

Are you running more than one application? If so, you might want to 
troubleshoot your mod_wsgi setup, try turning one app off, etc. If you're 
running a single app, then I'm not sure... maybe check the apache config, 
ensure you're setting the right user and group to the wsgi daemon process 
as it could still be a permissions issue in that way... although it's 
curious that your app suddenly started creating 'unrecoverable' tickets.

I'm sure you're restarted apache and possibly the machine to make sure it's 
not just weirdness?

-Colin

On Wednesday, August 1, 2012 3:36:21 AM UTC-5, r13race wrote:

 Hello,

 I made an application using Apache+Web2py+WSGI framework.
 It was running fine and all of a sudden as i enter the URL of teh startup 
 page it directs me to index.html, it works fine.
 There i have a login button as i click it, it issues me a ticket 
 Unrecoverable
 Its not a problem of permissions i have checked.
 Can someone help me??


-- 





[web2py] Vars dictionary -- legal to have 'int'?

2012-08-01 Thread AbrahamLinksys
Hi,

I have an appilcation that has been running for a while, and suddenly today 
it gave an error on this line in my view:

  
  [a href={{=URL(r=request,args=request.args,vars=dict(all=1)) }}show 
all attachements/a]

This worked fine, but then I think I upgraded from 1.99.4 to 1.99.7, and it 
throws an error complaining that it cannot concatenate string and int types 
(because of dict(all=1) instead of all='1')

Of course, the error can be fixed by passing a string literal or calling 
str() on the int, but i was curious if this intended? 

I haven't been very careful to only use string vars, assuming that my 
laziness would be corrected by some gluonic magic. 

Am I supposed to have always been passing only strings as vars? Should I be 
proactive and hunt down places in my code in other applications (which are 
still using slightly older web2py versions) or is this something that might 
change back to being able to use integers? 

Just curious. Here's the relevant part of the traceback:

  File /usr/web2py-latest/gluon/html.py, line 330, in URL
other += '?%s' % ''.join([var[0]+'='+var[1] for var in list_vars])
TypeError: cannot concatenate 'str' and 'int' objects


If the other+= line were rewritten as such, would it be a bad thing for any 
reason?

other += '?%s' % ''.join([*str(*var[0]*)*+'='+str(var[1]) for var in 
list_vars])


Thanks,

Abe

-- 





Re: [web2py] Re: Vars dictionary -- legal to have 'int'?

2012-08-01 Thread AbrahamLinksys
Hmm, I tried again with a simpler example in an app built from the welcome 
app.

I got the same error, but I noticed this:

(a=None, c=None, f=None, r=Storage {'body': cStringIO.StringO object at 
0..._vars': Storage {}, 'post_vars': Storage {}}, args=[], vars={'a': 
2}, anchor='', extension=None, env=Storage {'debugging': False, 
'http_user_agent':...[]), 'query_string': '', 'wsgi_run_once': False}, 
hmac_key=None, hash_vars=True, salt=None, user_signature=None, scheme=None, 
host=None, port=None, encode_embedded_slash=False, *url_encode=False*)

As you can see, url_encode is set to false... I double checked the version, 
and it is 1.99.7 (i printed out request.env.web2py_version from the app 
just to be sure, as I have several web2py versions on the test server, so I 
possibly have done something silly somewhere). 

However, when I launch an app with python web2py.py -M -S app, I do not 
in fact get the error, leading me to believe I AM doing something silly. 

Any idea where I can look to see how the url_encode might be getting set to 
false?

On Wednesday, August 1, 2012 10:54:10 AM UTC-5, Jonathan Lundell wrote:

 On 1 Aug 2012, at 8:42 AM, Massimo Di Pierro massimo.dipie...@gmail.com 
 wrote:

 in trunk. please check it.


 Per my earlier message, this should not be necessary. There must be 
 something else wrong, and str() unfortunately just papers over whatever the 
 real problem is.


 On Wednesday, 1 August 2012 10:23:11 UTC-5, AbrahamLinksys wrote:

 Hi,

 I have an appilcation that has been running for a while, and suddenly 
 today it gave an error on this line in my view:

  
   [a href={{=URL(r=request,args=request.args,vars=dict(all=1)) }}show 
 all attachements/a]

 This worked fine, but then I think I upgraded from 1.99.4 to 1.99.7, and 
 it throws an error complaining that it cannot concatenate string and int 
 types (because of dict(all=1) instead of all='1')

 Of course, the error can be fixed by passing a string literal or calling 
 str() on the int, but i was curious if this intended? 

 I haven't been very careful to only use string vars, assuming that my 
 laziness would be corrected by some gluonic magic. 

 Am I supposed to have always been passing only strings as vars? Should I 
 be proactive and hunt down places in my code in other applications (which 
 are still using slightly older web2py versions) or is this something that 
 might change back to being able to use integers? 

 Just curious. Here's the relevant part of the traceback:

   File /usr/web2py-latest/gluon/html.py, line 330, in URL
 other += '?%s' % ''.join([var[0]+'='+var[1] for var in list_vars])
 TypeError: cannot concatenate 'str' and 'int' objects


 If the other+= line were rewritten as such, would it be a bad thing for 
 any reason?

 other += '?%s' % ''.join([*str(*var[0]*)*+'='+str(var[1]) for var in 
 list_vars])


 Thanks,

 Abe


 -- 
  




On Wednesday, August 1, 2012 10:54:10 AM UTC-5, Jonathan Lundell wrote:

 On 1 Aug 2012, at 8:42 AM, Massimo Di Pierro massimo.dipie...@gmail.com 
 wrote:

 in trunk. please check it.


 Per my earlier message, this should not be necessary. There must be 
 something else wrong, and str() unfortunately just papers over whatever the 
 real problem is.


 On Wednesday, 1 August 2012 10:23:11 UTC-5, AbrahamLinksys wrote:

 Hi,

 I have an appilcation that has been running for a while, and suddenly 
 today it gave an error on this line in my view:

  
   [a href={{=URL(r=request,args=request.args,vars=dict(all=1)) }}show 
 all attachements/a]

 This worked fine, but then I think I upgraded from 1.99.4 to 1.99.7, and 
 it throws an error complaining that it cannot concatenate string and int 
 types (because of dict(all=1) instead of all='1')

 Of course, the error can be fixed by passing a string literal or calling 
 str() on the int, but i was curious if this intended? 

 I haven't been very careful to only use string vars, assuming that my 
 laziness would be corrected by some gluonic magic. 

 Am I supposed to have always been passing only strings as vars? Should I 
 be proactive and hunt down places in my code in other applications (which 
 are still using slightly older web2py versions) or is this something that 
 might change back to being able to use integers? 

 Just curious. Here's the relevant part of the traceback:

   File /usr/web2py-latest/gluon/html.py, line 330, in URL
 other += '?%s' % ''.join([var[0]+'='+var[1] for var in list_vars])
 TypeError: cannot concatenate 'str' and 'int' objects


 If the other+= line were rewritten as such, would it be a bad thing for 
 any reason?

 other += '?%s' % ''.join([*str(*var[0]*)*+'='+str(var[1]) for var in 
 list_vars])


 Thanks,

 Abe


 -- 
  





-- 





[web2py] Re: Vars dictionary -- legal to have 'int'?

2012-08-01 Thread AbrahamLinksys
Wow, I certainly did something silly at some point -- in my source 
(gluon/html.py), url_encode is set to false:

I checked out a new version, and the build times match 100%, so it HAS to 
be my silliness (Version 1.99.7 (2012-03-04 22:12:08) stable).  

Apologies for the wild goose chase -- I seem to remember debugging some 
issue I was having with URLs from another app that linked to this one... 
anyway, I clearly was careless in that I modified the source and forgot to 
change it back.

Thanks for your help. 

-Abe

On Wednesday, August 1, 2012 10:23:11 AM UTC-5, AbrahamLinksys wrote:

 Hi,

 I have an appilcation that has been running for a while, and suddenly 
 today it gave an error on this line in my view:

   
   [a href={{=URL(r=request,args=request.args,vars=dict(all=1)) }}show 
 all attachements/a]

 This worked fine, but then I think I upgraded from 1.99.4 to 1.99.7, and 
 it throws an error complaining that it cannot concatenate string and int 
 types (because of dict(all=1) instead of all='1')

 Of course, the error can be fixed by passing a string literal or calling 
 str() on the int, but i was curious if this intended? 

 I haven't been very careful to only use string vars, assuming that my 
 laziness would be corrected by some gluonic magic. 

 Am I supposed to have always been passing only strings as vars? Should I 
 be proactive and hunt down places in my code in other applications (which 
 are still using slightly older web2py versions) or is this something that 
 might change back to being able to use integers? 

 Just curious. Here's the relevant part of the traceback:

   File /usr/web2py-latest/gluon/html.py, line 330, in URL
 other += '?%s' % ''.join([var[0]+'='+var[1] for var in list_vars])
 TypeError: cannot concatenate 'str' and 'int' objects


 If the other+= line were rewritten as such, would it be a bad thing for any 
 reason?

 other += '?%s' % ''.join([*str(*var[0]*)*+'='+str(var[1]) for var in 
 list_vars])


 Thanks,

 Abe



-- 





[web2py] Re: Apache wsgi virtualhost configuration for multiple web2py sites

2012-07-12 Thread AbrahamLinksys
Does anyone know how to use mod_wsgi with multiple virtualhosts?

I have 2 domains:
  project1.uni.edu
  project2.uni.edu

And I want to be able to omit the project names from the URL path, as such:

http://project1.uni.edu/ - http://project1.uni.edu/project1/default/index
http://project2.uni.edu/ - http://project2.uni.edu/project2/default/index

It is IMPORTANT that the project name does not HAVE TO show up after in the 
URL path after the domain at all, because there are a lot of legacy links 
circulated before the web2py app was even written.

Both domains are FQDNs -- I don't have access to uni.edu zones or any 
configuration like that. Both DNs point to the same server, where I have 
two virtualhosts (defined below). Also, just to make things fun, soon we 
will have sub1.project2.uni.edu, sub2.project2.uni.edu, etc. Project1 will 
not branch anymore. 

The thing is, for project1, I set web2py up to not have to include the app 
name, since it's called project1 as well. Furthermore, both projects must 
be able to use mod_user to show websites of users belonging to the projects 
(meaning they are different user directories). They also both have AWStats 
running (hence the WSGIScriptAliasMatch below).

Now, my question (apologies to G. Dumpleton for my inability to understand) 
is about the WSGI ProcessGroup/ApplicationGroup settings.

As I understand it, if I want to use two virtualhosts with one instance of 
web2py over mod_wsgi, I must define the WSGIDaemonProcess outside of the 
virtualhosts, and use WSGIProcessGroup with the name I defined in 
WSGIDaemonProcess. Or I could define two separate WSGIDaemonProcesses 
within the vhosts, but give them unique names. Does anyone know the 
ramifications of choosing 1 method over the other?

My other question is about the WSGIApplicationGroup setting -- I see I can 
set it to %{GLOBAL}, %{SERVER}, %{RESOURCE} or %{ENV:var}. Does anyone know 
if setting both to %GLOBAL is ok? Or should I use %{RESOURCE} to keep them 
from executing in the same interpreter (or process? I'm admittedly 
ill-informed about these settings...). Is this setting affected by my 
choice of single vs multiple WSGIDaemonProcess definitions?

Currently my conf files are as such:

Virtualhost *:80
  ServerName project1.uni.edu


  WSGIDaemonProcess web2py user=www-user group=www-group processes=3 
threads=5 \
   display-name=%{GROUP}
  WSGIProcessGroup web2py
  WSGIApplicationGroup %{GLOBAL} 


  WSGIScriptAliasMatch ^(/([^~].*|awstats.*)?)$ 
/var/www/web2py/wsgihandler.py$1


  #... more stuff including web2py-static via apache, locking admin, 
user_dirs, awstats conf, etc...  
/Virtualhost


VirtualHost *:80
  ServerName project2.uni.edu
  WSGIDaemonProcess project2 user=www-user group=www-group processes=3 
threads=5 \
   display-name=%{GROUP}
  WSGIProcessGroup project2
  WSGIApplicationGroup %{RESOURCE} 
  WSGIScriptAliasMatch ^(/([^~].*|awstats.*)?)$ 
/var/www/web2py/wsgihandler.py$1


  #... more stuff including web2py-static via apache, locking admin, 
user_dirs, awstats conf, etc...
/Virtualhost

I want to change the project1 AppGroup to be RESOURCE as well to see if 
that has the desired effect, but I cannot do that at the moment since 
proejct1 is in production. 

LAST question: If I were to redo this configuration file to sit in a single 
vhost (forgetting about the mod_user/awstats for now), would the 
default_application = project1 setting totally screw me on project2 URLs? 
If so, are there any severe disadvantages to having two separate instances 
of web2py ... or even better, is it possible to specify the application 
based on the request host? perhaps in the app-specific routes file 
something like:

routers = dict(
  BASE  = dict(default_application='project1' if request.env.http_host == 
'project1.uni.edu' else 'project2'),
)



I guess I'm not sure if the routers can be set from within an 
application, or if that will royally hose things.

well, thanks in advance to anyone who responds!

-Abraham

On Sunday, October 17, 2010 5:21:21 PM UTC-5, Tom A wrote:

 I know this has been asked before but I've been unable to find a clear 
 answer. (Apologies to Graham Dumpleton who must have answered this kind of 
 question many times for Django etc but I can't work out how to do it for 
 web2py)

 I have a Debian server set up and running web2py with mod_wsgi using the 
 instructions in the book.  All works great.

 The file /etc/apache2/sites-available/default has the virtualhost 
 directives as shown in the book. So at the moment any request to the server 
 simply shows the welcome app.

 I have 3 domain names which resolve to the IP address of the server:

 - domain1.com
 - domain2.com
 - domain3.com

 I have a web2py application for each of these.  They are in 
 /var/www/web2py/applications/domain1 etc.

 So now I want to create 3 files in /etc/apache2/sites-available that will 
 get apache to serve up the appropriate 

Re: [web2py] Re: Apache wsgi virtualhost configuration for multiple web2py sites

2012-07-12 Thread AbrahamLinksys
Ah -- i had forgotten that you can have the domains dictionary in 
routers.BASE -- thanks!

I think this will help indeed. Do you know if I can use ports in the domain 
dict key? I would like to test this out on another port so that the live 
site isn't affected and the placeholder site for project2 can remain a 
static HTML placeholder site (it does get hit occasionally). 

For others' reference, I think this is the solution I will go with -- using 
1 installation of web2py, 1 Vhost with a single WSGIDaemonProcess 
definition, and I will put the following web2py-global routes.py file: 


routers = dict(
  # base router
  BASE = dict(
default_application = 'welcome',
domains = {
  'project1.uni.edu': 'project1',
  'www.project1.uni.edu': 'project1',
  'project2.uni.edu' : 'project2',
  'www.project2.uni.edu' : 'project2'
}
  )
)


I'll post back here regarding the status of this next week, as I'll be testing 
this setup over the weekend. 


Thanks again!

-Abe 

--

The trouble with quotes from the internet is that it's hard to verify 
their authenticity - Abraham Lincoln

On Thursday, July 12, 2012 3:00:48 PM UTC-5, Martin.Mulone wrote:

 perhaps this can help you


 http://martin.tecnodoc.com.ar/post/2012/02/08/14_setup-virtual-hosting-with-web2py-and-apache2-mod-wsgi-on-ubuntu-server-1110


 I am interested in a little different setup, I would like
 *.example.com to go to the web2py app/folder but be able to specify
 other.example.com be served from /var/www/other/

 I am having trouble figuring out how to configure Apache virtual host
 to do this.

 Thanks
 Vincent

 On Oct 18, 7:07 pm, VP vtp2...@gmail.com wrote:
  The way I did this is through Apache, by adding
 
  ServerName domain.com
  ServerAlias *.domain.com
 
  to the web2py configuration section in site-enabled/000-default
 
  Which one is more preferable?  pros and cons?
 
  Thanks.




 -- 
  http://www.tecnodoc.com.ar



[web2py] Re: Connection timed out - mysql

2012-07-12 Thread AbrahamLinksys
I get these broken pipe errors almost daily now, usually in the wee hours 
of the morning (between 1-5am). I'll get one or two, or sometimes like 5, 
but probably not more than say 10/day (on one page that pulls four images 
from the DB, i will get 4 at once), and it doesn't happen every day.  

I am storing images (100KB) in the database, but I'm not sure if that's 
it. I'm also hosting this on VMs (one for web2py, one for mysql DB server), 
and a few months ago I had never seen this error. It might be something to 
do with the VM setup but I'm really not sure. 

From what I understand, broken pipe happens at the OS level and is 
something to do with transferring information from the DB server... sound 
right?


Also, (separate issue, possibly related?) sometimes the website becomes 
unresponsive, and I get errors to do with base64 decoding and assertion 
errors:

 File /var/www/web2py/gluon/dal.py, line 5481, in select
return self.db._adapter.select(self.query,fields,attributes)
  File /var/www/web2py/gluon/dal.py, line 1192, in select
return self.parse(rows,self._colnames)
  File /var/www/web2py/gluon/dal.py, line 1421, in parse
colset[fieldname] = base64.b64decode(str(value))
  File /usr/lib64/python2.6/base64.py, line 76, in b64decode
raise TypeError(msg)
TypeError: Incorrect padding


and : 

Error: (type 'exceptions.AssertionError', AssertionError('Result length 
not requested length:\nExpected=97.  Actual=31.  Position: 299.  Data 
Length: 330',))

The odd thing is that I can do these queries via mysql command line, even 
when running mysql on the webserver to connect to the DB host, and they 
return instantly... although I guess I'm not sure if the assertion error 
comes from MySQL or is part of web2py's DB adapter?
We used wireshark to determine that the TCP packets were being incessantly 
retransmitted ... but only sometimes. The Padding/Assertion Errors seem to 
be related to VMs since migrating the machine to a different physical host 
and back resolves the issue immediately. 

Also, restarting httpd tends to lessen the amount of Broken Pipe errors I 
see, so perhaps it's some sort of stale connection to the DB?

-Abe

On Thursday, July 12, 2012 2:02:01 PM UTC-5, Marcello wrote:

 Hello,

 I'm having Connection timed out to mysql server.
 I'm creating a sheet from some queries. The function is in a module, and 
 running it from console.

 Sometimes, it goes OK, but sometimes I get the error (see below).

 I'm using EC2 and the database is in RDS.

 Thanks for any help...

 Marcello

 -
 Traceback (most recent call last):
   File /home/tecno2/web2py/gluon/shell.py, line 206, in run
 execfile(startfile, _env)
   File applications/segundarj/private/diario.py, line 2, in module
 planilha.roda(True)
   File applications/segundarj/modules/planilha.py, line 64, in roda
 print aba: %s, total: %s % (aba,processos.count())
   File /home/tecno2/web2py/gluon/dal.py, line 7573, in count
 return self.db._adapter.count(self.query,distinct)
   File /home/tecno2/web2py/gluon/dal.py, line 1339, in count
 self.execute(self._count(query, distinct))
   File /home/tecno2/web2py/gluon/dal.py, line 1392, in execute
 return self.log_execute(*a, **b)
   File /home/tecno2/web2py/gluon/dal.py, line 1386, in log_execute
 ret = self.cursor.execute(*a, **b)
   File /home/tecno2/web2py/gluon/contrib/pymysql/cursors.py, line 108, 
 in execute
 self.errorhandler(self, exc, value)
   File /home/tecno2/web2py/gluon/contrib/pymysql/connections.py, line 
 182, in defaulterrorhandler
 raise Error(errorclass, errorvalue)
 Error: (class 'socket.error', error(110, 'Connection timed out'))

 Traceback (most recent call last):
   File web2py.py, line 20, in module
 gluon.widget.start(cron=True)
   File /home/tecno2/web2py/gluon/widget.py, line 868, in start
 import_models=options.import_models, startfile=options.run)
   File /home/tecno2/web2py/gluon/shell.py, line 210, in run
 if import_models: BaseAdapter.close_all_instances('rollback')
   File /home/tecno2/web2py/gluon/dal.py, line 432, in close_all_instances
 getattr(instance, action)()
   File /home/tecno2/web2py/gluon/dal.py, line 1357, in rollback
 return self.connection.rollback()
   File /home/tecno2/web2py/gluon/contrib/pymysql/connections.py, line 
 571, in rollback
 self.errorhandler(None, exc, value)
   File /home/tecno2/web2py/gluon/contrib/pymysql/connections.py, line 
 182, in defaulterrorhandler
 raise Error(errorclass, errorvalue)
 gluon.contrib.pymysql.err.Error: (class 'socket.error', error(32, 
 'Broken pipe'))



[web2py] Re: Problems setting up apache to proxy traffic

2012-06-08 Thread AbrahamLinksys
I think you forgot the trailing slash on ProxyPass:

*ProxyPass http://localhost:8000/*
*
*
That's why the DNS lookup failed I think: Reason: strongDNS lookup 
failure for: localhost:8000welcome/strong/p/p



On Friday, June 8, 2012 6:01:21 AM UTC-5, Robin Wood wrote:

 Hi
 I'm trying to setup apache to proxy traffic into web2py. I've followed the 
 instructions I can find but I'm getting problems.

 I've got the following in my apache config

 ProxyRequests off
 location /
 ProxyPass http://localhost:8000
 ProxyPassReverse /
 /location

 Which is successfully redirecting from localhost port 80 to web2py on port 
 8000.

 root@web2py:~# curl localhost -v
 * About to connect() to localhost port 80 (#0)
 *   Trying 127.0.0.1... connected
  GET / HTTP/1.1
  User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 
 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
  Host: localhost
  Accept: */*
  
  HTTP/1.1 303 SEE OTHER
  Date: Fri, 08 Jun 2012 10:58:21 GMT
  Server: Rocket 1.2.4 Python/2.7.3
  Content-Type: text/html; charset=UTF-8
  Location: http://localhost/welcome/default/index
  Content-Length: 66
  Vary: Accept-Encoding
  
 * Connection #0 to host localhost left intact
 * Closing connection #0
 You are being redirected a href=/welcome/default/indexhere/a

 The problem is the redirection fails

 curl localhost/welcome/default/index -v
 * About to connect() to localhost port 80 (#0)
 *   Trying 127.0.0.1... connected
  GET /welcome/default/index HTTP/1.1
  User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 
 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
  Host: localhost
  Accept: */*
  
  HTTP/1.1 502 Proxy Error
  Date: Fri, 08 Jun 2012 10:59:34 GMT
  Vary: Accept-Encoding
  Content-Length: 509
  Content-Type: text/html; charset=iso-8859-1
  
 !DOCTYPE HTML PUBLIC -//IETF//DTD HTML 2.0//EN
 htmlhead
 title502 Proxy Error/title
 /headbody
 h1Proxy Error/h1
 pThe proxy server received an invalid
 response from an upstream server.br /
 The proxy server could not handle the request ema 
 href=/welcome/default/indexGETnbsp;/welcome/default/index/a/em.p
 Reason: strongDNS lookup failure for: 
 localhost:8000welcome/strong/p/p
 hr
 addressApache/2.2.22 (Ubuntu) Server at localhost Port 80/address
 /body/html
 * Connection #0 to host localhost left intact
 * Closing connection #0

 For some messing up the hostname and trying to redirect to a host that 
 doesn't exist.

 This is on a newly installed Ubuntu box and web2py is working fine when 
 just accessed on port 8000.

 Can anyone tell me what I've done wrong?

 Thanks

 Robin