The given path is misformatted or contained invalid characters: Apache Error - regex

I am using apache2.2 on windows environment. I have ssi to be include the content such as :
<!--#include virtual="/content/app/en/jcr:content/test.html" -->
Its giving an error below :
[Fri Jan 29 14:53:09 2016] [error] [client 127.0.0.1] (20024)The given path is misformatted or contained invalid characters: Cannot map GET /content/app/en/myPage.html HTTP/1.1 to file
[Fri Jan 29 14:53:09 2016] [error] [client 127.0.0.1] unable to include "/content/app/en/jcr:content/test.html" in parsed file
I have tried using /:, but no effect. On browser its giving error :[an error occurred while processing this directive]

Windows does not allow : in its folder names so apache is unable to map it to a file on disk. This should not happen on linux.
If possible, use _jcr_content instead of jcr:content in the above path.

Related

Telegram-bot (telepot api): Is it possible to send an image directly from URL without saving it

Im writing a telegram bot using the python telepot api. I'm now stuck at the point where I want to send a picture which directly comes from an URL without storing it locally. Telepot provides the following instruction to send a photo:
>>> f = open('zzzzzzzz.jpg', 'rb') # some file on local disk
>>> response = bot.sendPhoto(chat_id, f)
Now im using
f = urllib2.urlopen('http://i.imgur.com/B1fzGoh.jpg')
bot.sendPhoto(chat_id, f)
The problem here is that urllib2.urlopen('url') provide me file-like object like:
<addinfourl at 140379102313792 whose fp = <socket._fileobject object at 0x7fac8e86d750>>
and not like open('myFile.jpg', 'rb') a file object like:
<open file 'app-root/runtime/repo/myImage.jpg', mode 'rb' at 0x7fac8f322540>
If I send the file-like object in sendPhoto() I get the following error:
Traceback (most recent call last):
[Wed Feb 10 06:21:09 2016] [error] File "/var/lib/openshift/56b8e2787628e1484a00013e/python/virtenv/lib/python2.7/site-packages/telepot/__init__.py", line 340, in handle
[Wed Feb 10 06:21:09 2016] [error] callback(update['message'])
[Wed Feb 10 06:21:09 2016] [error] File "/var/lib/openshift/56b8e2787628e1484a00013e/app-root/runtime/repo/moviequiz_main.py", line 35, in handle
[Wed Feb 10 06:21:09 2016] [error] response = bot.sendPhoto(chat_id, gif)
[Wed Feb 10 06:21:09 2016] [error] File "/var/lib/openshift/56b8e2787628e1484a00013e/python/virtenv/lib/python2.7/site-packages/telepot/__init__.py", line 230, in sendPhoto
[Wed Feb 10 06:21:09 2016] [error] return self._sendFile(photo, 'photo', p)
[Wed Feb 10 06:21:09 2016] [error] File "/var/lib/openshift/56b8e2787628e1484a00013e/python/virtenv/lib/python2.7/site-packages/telepot/__init__.py", line 226, in _sendFile
[Wed Feb 10 06:21:09 2016] [error] return self._parse(r)
[Wed Feb 10 06:21:09 2016] [error] File "/var/lib/openshift/56b8e2787628e1484a00013e/python/virtenv/lib/python2.7/site-packages/telepot/__init__.py", line 172, in _parse
[Wed Feb 10 06:21:09 2016] [error] raise BadHTTPResponse(response.status_code, response.text)
[Wed Feb 10 06:21:09 2016] [error] BadHTTPResponse: (414, u'<html>\\r\\n<head><title>414 Request-URI Too Large</title></head>\\r\\n<body bgcolor="white">\\r\\n<center><h1>414 Request-URI Too Large</h1></center>\\r\\n<hr><center>nginx/1.9.1</center>\\r\\n</body>\\r\\n</html>\\r\\n')
There is a solution for a different telegram-bot project provided here where they send the urllib2.urlopen('url').read() back to telegram but in my case this generates the same error as without .read() .
How could I get the file from the url as file object (best would be without saving it locally)?
Or how do I get the "file object" out of the "file-like object" provided by urlopen()?
Thanks for any help :)
In current Bot Api 2.3.1, You can simply send url of file to the server:
bot.sendPhoto(chat_id, "http://i.imgur.com/B1fzGoh.jpg");
That's it.
You don't even need to download it, Telegram would upload it by itself.
Yes.
You can make it async (or not):
async with aiohttp.get("http://i.imgur.com/B1fzGoh.jpg") as r:
result = r.read()
await self.sendPhoto(chat_id, ('image.jpg', result))

How can I debug a 503 error with Django on Apache?

I pushed an update to my site earlier today, and when I tried to connect to it, received a Gateway Time-out error (503).
This is my error log :
[Wed Nov 04 01:34:26 2015] [error] [client 128.79.79.108] Timeout when reading response headers from daemon process 'elandemdaemon': /home/python/home/elandem/edem/edem/wsgi.py
[Wed Nov 04 01:38:39 2015] [error] [client 66.249.79.153] Timeout when reading response headers from daemon process 'elandemdaemon': /home/python/home/elandem/edem/edem/wsgi.py
[Wed Nov 04 01:39:26 2015] [error] [client 128.79.79.108] Timeout when reading response headers from daemon process 'elandemdaemon': /home/python/home/elandem/edem/edem/wsgi.py
[Wed Nov 04 01:40:18 2015] [error] [client 109.190.112.58] Timeout when reading response headers from daemon process 'elandemdaemon': /home/python/home/elandem/edem/edem/wsgi.py
And here are the contents of my wsgi.py file :
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "edem.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
I reverted my changes (minor things), but the issue remains. Was it just a coincidence that the issue happend right after an update ?
When I load the site with runsever 0.0.0.0:8000, it works fine.
Is there a step-by-step way to check where this issue may be occuring ?

What type of delimiter should i use in Pig Latin to process apache log?

If this is how my Apache log looks, what delimiter should I use in PigLatin to split the data.
[Mon Jul 02 10:04:18 2012] [error] [client x.x.x.x] File does not exist: /home/ec2- user/xxxxxxxxxx/xxxxxxxxx, referer: http://xxxx/xxxxx/xxxxx/
I tried PigStorage(',') to split the referer and the other string. But how can I split
[Mon Jul 02 10:04:18 2012] [error] [client x.x.x.x] File does not exist: /home/ec2-user/xxxxxxxxxx/xxxxxxxxx
If I use space as the delimiter Mon Jul 02 10:04:18 2012 gets split into multiple string.
Have you tried the Log Loaders, as part of Piggybank?
http://kickstarthadoop.blogspot.com/2011/06/analyzing-apache-logs-with-pig.html
http://www.cloudera.com/blog/2009/06/analyzing-apache-logs-with-pig/
That's what I use:
REGISTER /usr/local/pig-0.10.0/contrib/piggybank/java/piggybank.jar;
A = load '*.log'
USING org.apache.pig.piggybank.storage.MyRegExLoader(
'(DATETIMEREX) (ERROREX) (CLIENTEX) (.*)')
AS (
dateTime : chararray,
error : chararray,
client : chararray,
line : chararray );
Susbtitute the DATETIMEX, ERROREX, CLIENTEX with the appropriate regular expressions.

Setting up Apache and Python WSGI to use VirtualEnv

I'm having trouble getting Apache/WSGI to use my VirtualEnv. I have added the following two lines (path on server is pointing to the actual location of site-packages in the target virtualenv) to my WSGI file:
import site
site.addsitedir('/sites/mysite/virtpy/lib/python2.6/site-packages')
(from http://www.foxhop.net/django-virtualenv-apache-mod_wsgi). However, when I try to load the url in the browser I get a 500. Checking the apache logs:
[Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] app = import_module(appname)
[Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
[Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] __import__(name)
[Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] TemplateSyntaxError: Caught ImportError while rendering: No module named tagging
[Sun Jul 17 11:07:11 2011] [debug] mod_deflate.c(615): [client 94.170.105.142] Zlib: Compressed 629 to 387 : URL /
So I guess that the VirtualEnv isn't being loaded. Anyone know how to tell Apache / WSGI the correct virtualenv to use?
UPDATE
I have updated django.wsgi following Ken's advice, but now I am getting the following error in the apache log
[Sun Jul 17 16:46:36 2011] [info] [client 94.170.105.142] mod_wsgi (pid=11260, process='', application='igniteflow-django.com:8090|'): Loading WSGI script '/sites/igniteflow/apache/django.wsgi'.
[Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] mod_wsgi (pid=11260): Target WSGI script '/sites/igniteflow/apache/django.wsgi' cannot be loaded as Python module.
[Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] mod_wsgi (pid=11260): Exception occurred processing WSGI script '/sites/igniteflow/apache/django.wsgi'.
[Sun Jul 17 16:46:36 2011] [error] [client 94.170.106.142] Traceback (most recent call last):
[Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] File "/sites/igniteflow/apache/django.wsgi", line 5, in <module>
[Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] execfile(activate_this, dict(__file__=activate_this))
[Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] IOError: [Errno 13] Permission denied: '/root/.virtualenvs/igniteflow/bin/activate_this.py'
I assume this is because the virtualenv is in root and apache doesn't have permissions? I chowned the folder to root:www-data but it hasn't fixed the problem. Any suggestions?
In my app.wsgi file I have something like this. You will need to change it to put to where your virtual env is located, mine is under /opt/ve/ve_name/ in this example.
import os
# activate virtualenv
activate_this = os.path.expanduser("/opt/ve/ve_name/bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))

Django: Moving from development server to deployment (Apache+mod_wsgi)

I'm developing application on Django, and ready to move to deployment server. I'm able to run a new django project on apache(I can see the welcome page).
However, when I copy my original project's files to apache project directory, I start getting errors. Here is a sample from apache/error.log.
[Wed Jan 26 19:22:08 2011] [error] [client 127.0.0.1] TemplateSyntaxError: Caught ImportError while rendering: No module named charts
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] mod_wsgi (pid=4670): Exception occurred processing WSGI script '/srv/www/enpass/apache/django.wsgi'.
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] Traceback (most recent call last):
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 241, in __call__
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] response = self.get_response(request)
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 141, in get_response
My django.wsgi file looks like
import os
import sys
path = '/srv/www'
if path not in sys.path:
sys.path.insert(0, '/srv/www')
os.environ['DJANGO_SETTINGS_MODULE'] = 'enpass.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I've changed all the paths in files to suit the new directory structure, so I'm pretty sure thats not the problem. FIY, I followed the steps given in this tutorial http://blog.stannard.net.au/2010/12/11/installing-django-with-apache-and-mod_wsgi-on-ubuntu-10-04/
I figured it out myself. We need to add the project directory path to sys.path. The following code solved the problem in django.wsgi
path = '/srv/www/enpass'
if path not in sys.path:
sys.path.append(path)
Looks like you are missing the charts module..
install pip
sudo easy_install pip
list packages
pip freeze
do the same on the development machine and look for a chart module, then install it on the production server with
sudo pip install <packagename>