Closed rdavrin closed 5 years ago
I suspect the error lies here (1). Do you use your own SSL certificate? Are you sure you have the latest version of MuK Utils?
(1) /usr/lib/python3/dist-packages/odoo/addons/muk_utils/tools/http.py
Hi, thanks for your prompt reply.
In regards to SSL, the site uses a proper SSL Certificate from a Certificate Authority
And for the version of MuK utils, I downloaded those from the Odoo Apps download website. Please advise if this is the latest version that I should be using
Kind regards
Richard
The store is the right place, but you might have an older version
I did a:
$ git clone https://github.com/muk-it/muk_base.git
And copied muk_base/muk_utils to the addons directory and then Updated Odoo modules and re-installed the required MUK util app. I got exactly the same error
File "/usr/lib/python3/dist-packages/odoo/http.py", line 515, in response_wrap response = f(*args, **kw) File "/usr/lib/python3/dist-packages/odoo/addons/muk_web_preview_msoffice/controllers/main.py", line 45, in preview_msoffice status, headers, content = get_response(url) File "/usr/lib/python3/dist-packages/odoo/addons/muk_utils/tools/http.py", line 60, in get_response return exception.response.status_code, exception.response.headers, exception.response.reason AttributeError: 'NoneType' object has no attribute 'status_code'
Please advise
Hi,
can you try some things and tell me what happens?
sudo -u odoo unoconv -f pdf filename.docx
sudo -u odoo python3
Then type:
import pdfconv as p
p.converter.convert_document2pdf("/path/to/input.docx", "/path/to/output.pdf")
If both work its probably a connection problem. Thats what keshrath and I think.
We ran in some issues there in the past (mostly with custom certificates or CAs that are not known to python) and are trying to solve this. If you look at the file muk_utils/tools/http.py [1] line 60 doesn't look like the line in your log anymore:
return exception.response.status_code, exception.response.headers, exception.response.reason
We disabled SSL verification until we resolve this issue.
Check if you have the same file and if not update this file or the whole module. Maybe you need to restart Odoo again.
[1] https://github.com/muk-it/muk_base/blob/11.0/muk_utils/tools/http.py
Regards, Kerrim
Hi team
It is the SSL issue. I disabled SSL on the environment completely and it can preview DOC and DOCX documents now
Funny thing is that my Odoo installation is non-encrypted and I have an Apache Web Server that sits in front of it and does a reverse proxy to the Odoo installation non-encrypted
The SSL termination is at the Apache Server. Should that pose an issue
Please advise guys... Thank you for your input as always
Kind regards
Richard
Hi team
Wanted to check with you, is there any solutions available that would allow the site to use SSL in the setup that I have described above, ie non-encrypted Odoo with SSL terminating at Apache
Please advise
base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url')
method, params, path = get_route(url)
params.update({'csrf_token': request.csrf_token()})
session = requests.Session()
session.cookies['session_id'] = request.session.sid
try:
response = session.post("%s%s" % (base_url, path), params=params, verify=False)
return response.status_code, response.headers, response.content
except:
_logger.info("Trying custom certificate")
custom_cert = config.get("muk_custom_certificate", False)
try:
_logger.info("Using Certificate: {}".format(custom_cert))
response = session.post("%s%s" % (base_url, path), params=params, verify=custom_cert)
return response.status_code, response.headers, response.reason
except:
try:
_logger.info("Custom Certificate didn't work")
response = session.post("%s%s" % (base_url, path), params=params, verify=False)
return response.status_code, response.headers, response.reason
except Exception as e:
_logger.exception("Request failed!")
return 501, [], str(e)
The reason for this that I resolve a relativ URL by building a new session and calling it. This produces an outside call through Apache. I will rework the method since this makes not a lot of sense.
Till then you can try to set the SSL certificate via the muk_custom_certificate
config parameter.
Thanks for you insight and the code above.. I have enhanced http.py with the above code and got the following warning:
2018-09-21 01:15:36,424 17266 WARNING eventdevdb py.warnings: /usr/lib/python3/dist-packages/urllib3/connectionpool.py:854: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised
I have enhanced the code with the following to get rid of these warnings and their effects down the pipe.
At the command line pip install urllib3
In the code: ... import urllib3 ... if not bool(urllib.parse.urlparse(url).netloc): urllib3.disable_warnings() base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url')
That got rid of the warnings in the logs. I am now getting the following error:
2018-09-21 01:21:21,445 17858 ERROR eventdevdb odoo.addons.muk_web_preview_msoffice.controllers.main: Error while convert the file. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/odoo/addons/muk_web_preview_msoffice/controllers/main.py", line 53, in preview_msoffice output = request.env['muk_converter.converter'].convert(filename, content) File "/usr/lib/python3/dist-packages/odoo/addons/muk_converter/models/converter.py", line 47, in convert checksum = hashlib.sha1(content).hexdigest() TypeError: Unicode-objects must be encoded before hashing
Please advise
https://github.com/muk-it/muk_base/blob/11.0/muk_converter/models/converter.py
Can you print out the content and send me the log.
Here is converter.py on the system:
import hashlib import logging
from odoo import api, models, fields from odoo.addons.muk_converter.tools import converter
_logger = logging.getLogger(name) class Converter(models.AbstractModel): _name = 'muk_converter.converter' _description = 'Converter'
@api.model
def convert(self, filename, content, format="pdf", recompute=False):
def parse(filename, content, format):
return converter.convert(filename, content, format)
def store(checksum, filename, content, format, stored):
if not stored.exists():
self.env['muk_converter.store'].sudo().create({
'checksum': checksum,
'format': format,
'content_fname': filename,
'content': content})
else:
stored.write({'used_date': fields.Datetime.now})
checksum = hashlib.sha1(content).hexdigest()
stored = self.env['muk_converter.store'].sudo().search(
[["checksum", "=", checksum], ["format", "=", format]], limit=1)
if not recompute and stored.exists():
return stored.content
else:
output = parse(filename, content, format)
name = "%s.%s" % (filename, format)
store(checksum, name, output, format, stored)
return output
And please find a copy of the error in the log:
2018-09-21 06:23:48,564 9712 INFO eventdevdb werkzeug: 10.0.0.11 - - [21/Sep/2018 06:23:48] "GET /web/content?model=muk_dms.file&filename=TestDoc.doc&filename_field=name&field=content&id=137&download=true&csrf_token=905de1db180c86e14f3081fc6612e5c411c954fdo1537514628 HTTP/1.1" 200 - 2018-09-21 06:23:48,566 9712 INFO eventdevdb odoo.addons.muk_utils.tools.http: Trying custom certificate 2018-09-21 06:23:48,566 9712 INFO eventdevdb odoo.addons.muk_utils.tools.http: Using Certificate: False 2018-09-21 06:23:48,578 9712 INFO eventdevdb werkzeug: 10.0.0.11 - - [21/Sep/2018 06:23:48] "GET /web/content?model=muk_dms.file&filename=TestDoc.doc&filename_field=name&field=content&id=137&download=true&csrf_token=905de1db180c86e14f3081fc6612e5c411c954fdo1537514628 HTTP/1.1" 200 - 2018-09-21 06:23:48,580 9712 ERROR eventdevdb odoo.addons.muk_web_preview_msoffice.controllers.main: Error while convert the file. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/odoo/addons/muk_web_preview_msoffice/controllers/main.py", line 53, in preview_msoffice output = request.env['muk_converter.converter'].convert(filename, content) File "/usr/lib/python3/dist-packages/odoo/addons/muk_converter/models/converter.py", line 47, in convert checksum = hashlib.sha1(content).hexdigest() TypeError: Unicode-objects must be encoded before hashing 2018-09-21 06:23:48,581 9712 INFO eventdevdb werkzeug: 10.0.0.11 - - [21/Sep/2018 06:23:48] "GET /web/preview/msoffice?url=%2Fweb%2Fcontent%3Fmodel%3Dmuk_dms.file%26filename%3DTestDoc.doc%26filename_field%3Dname%26field%3Dcontent%26id%3D137%26download%3Dtrue HTTP/1.1" 500 -
checksum = hashlib.sha1(content).hexdigest()
This line causes the error. So can you do something like: _logger.info(content)
Before the line which causes the error.
Added the logger line and there is one additional line in the logs, which i have highlighted. The rest is the same
2018-09-21 06:45:21,856 28375 INFO eventdevdb odoo.addons.muk_utils.tools.http: Using Certificate: False 2018-09-21 06:45:21,867 28375 INFO eventdevdb werkzeug: 10.0.0.11 - - [21/Sep/2018 06:45:21] "GET /web/content?model=muk_dms.file&filename=TestDocx.docx&filename_field=name&field=content&id=136&download=true&csrf_token=03d9cf46320ed84ff67c3059ead9a0deb19fb3b3o1537515921 HTTP/1.1" 200 -
2018-09-21 06:45:21,873 28375 INFO eventdevdb odoo.addons.muk_converter.models.converter: OK
2018-09-21 06:45:21,873 28375 ERROR eventdevdb odoo.addons.muk_web_preview_msoffice.controllers.main: Error while convert the file. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/odoo/addons/muk_web_preview_msoffice/controllers/main.py", line 53, in preview_msoffice output = request.env['muk_converter.converter'].convert(filename, content) File "/usr/lib/python3/dist-packages/odoo/addons/muk_converter/models/converter.py", line 48, in convert checksum = hashlib.sha1(content).hexdigest() TypeError: Unicode-objects must be encoded before hashing
Hm ok, I have to say i don't know why the content contains Ok as his value. I will test this out myself and get back to you if i can reproduce your error. But this will take a week or so, cause I'm out of office at the moment
Thanks for this. In the meantime, I'll attempt to re-install the Muk MSOffice Preview modules on a clean Odoo 11 build with Apache and SSL at the font end. What would be the git commands that I should use to grab everything to install the MS-Office Preview from your perspective
You can give pip a try or just grab base and web
Team
I have had a success with pre-viewing DOC and DOCX files. What I did was to follow the install instructions in the link INSTEAD of installing the MUK modules from the Odoo App store
Here are the instructions that I followed on Ubuntu 17 running Odoo11
Install Odoo as per your usual install process, then:
apt-get install python3-pip sudo -H pip3 install odoo-autodiscover sudo -H pip3 install --extra-index-url https://nexus.mukit.at/repository/odoo/simple odoo11-addon-muk-dms sudo -H pip3 install odoo11-addon-base-location sudo -H pip3 install --extra-index-url https://nexus.mukit.at/repository/odoo/simple \ odoo11-addon-muk-autovacuum \ odoo11-addon-muk-quality-docs \ odoo11-addon-muk-web-preview-attachment \ odoo11-addon-muk-web-preview-audio \ odoo11-addon-muk-web-preview-csv \ odoo11-addon-muk-web-preview-image \ odoo11-addon-muk-web-preview-mail \ odoo11-addon-muk-web-preview-msoffice \ odoo11-addon-muk-web-preview-video \ odoo11-addon-muk-web-share
This will install the MUK modules in /usr/local/lib/python3.6/dist-packages/odoo/addons/
You may need to copy all the files to /usr/lib/python3/dist-packages/odoo/addons depending on your Odoo installation
Then just go to the Odoo Developer Mode, Update Apps List and install the MUK modules as normal
Once installed, you should be able to view DOC, DOCX, PPT, PPTX as well, That should be it to resolve this issue
Nice :) Thanks for sharing^^
how to use muk_custom_certificate parameter?
Hi,
I am facing an issue at the moment, where I am unable to generate a DOC and a DOCX preview after installing and using MuK Preview MS Office package. All other common file extensions such as XLS, XLSX, PDF, ODS and ODT all work fine. The issue only arises with DOC and DOCX files.
I have successfully converted DOC and DOCX files at the command line as follows:
unoconv -f pdf astrid.docx
My installation process is as follows:
pip3 install cachetools pip3 install --extra-index-url https://nexus.mukit.at/repository/odoo/simple odoo11-addon-muk-utils sudo apt-get install unoconv git clone https://github.com/muk-it/muk_web.git git clone https://github.com/keshrath/pdfconv.git cd pdfconv/ sudo python setup.py install
Install all Muk Modules in Odoo
reboot
The error in the Odoo logs are as follows:
tail /var/log/odoo/odoo-server.log
File "/usr/lib/python3/dist-packages/odoo/http.py", line 342, in _call_function return checked_call(self.db, *args, kwargs) File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 97, in wrapper return f(dbname, *args, *kwargs) File "/usr/lib/python3/dist-packages/odoo/http.py", line 335, in checked_call result = self.endpoint(a, kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 936, in call return self.method(*args, *kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 515, in response_wrap response = f(args, **kw) File "/usr/lib/python3/dist-packages/odoo/addons/muk_web_preview_msoffice/controllers/main.py", line 45, in preview_msoffice status, headers, content = get_response(url) File "/usr/lib/python3/dist-packages/odoo/addons/muk_utils/tools/http.py", line 60, in get_response return exception.response.status_code, exception.response.headers, exception.response.reason AttributeError: 'NoneType' object has no attribute 'status_code'
Can you please advise what the issue could be and a possible solution. I can provide further logs if required
Kind regards
Richard