Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Python3 #17

Open
aelmahmoudy opened this issue Aug 31, 2019 · 12 comments
Open

Migrate to Python3 #17

aelmahmoudy opened this issue Aug 31, 2019 · 12 comments

Comments

@aelmahmoudy
Copy link
Contributor

aelmahmoudy commented Aug 31, 2019

Python 2 end-of-life date is on 2020: http://legacy.python.org/dev/peps/pep-0373/

please migrate thawab to Python3.

@aelmahmoudy
Copy link
Contributor Author

I have done the migration in python3 branch, yet I get this error:

Traceback (most recent call last):
File "/usr/bin/thawab-gtk", line 5, in
from Thawab.gtkUi import main
File "/usr/share/thawab/Thawab/gtkUi.py", line 35, in
from Thawab.shamelaUtils import ShamelaSqlite, shamelaImport
File "/usr/share/thawab/Thawab/shamelaUtils.py", line 51, in
os.urandom(hashlen*3/4).encode('base64')[:hashlen]
TypeError: integer argument expected, got float

can you help ?

@saad440
Copy link

saad440 commented Sep 4, 2019

I haven't looked at the whole code yet but it looks like it is because of the division (hashlen*3/4) which comes out as a float, not an integer. May be convert it to an int first?

@aelmahmoudy
Copy link
Contributor Author

I changed the line to:
os.urandom(int(hashlen*3/4)).encode('base64')[:hashlen]

Now I get this error:
AttributeError: 'bytes' object has no attribute 'encode'

@saad440
Copy link

saad440 commented Sep 4, 2019

urandom() is probably returning bytes rather than a string. Try decode instead of encode.

@muayyad-alsadi
Copy link
Member

from base64 import b64encode
b64encode(os.urandom(int(hashlen*3/4)))[:hashlen]

@aelmahmoudy
Copy link
Contributor Author

aelmahmoudy commented Sep 5, 2019 via email

@aelmahmoudy
Copy link
Contributor Author

I modified baseWebApp.py in okasha as follows:

   return ("Redirect to "+ str(e.kw['location']),) 

So the first 2 exceptions are gone, yet the last exception occurs twice but
with different port numbers:

----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 33916)
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/paste/httpserver.py", line 1085, in process_request_in_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 364, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.6/socketserver.py", line 724, in __init__
    self.handle()
  File "/usr/lib/python3/dist-packages/paste/httpserver.py", line 459, in handle
    BaseHTTPRequestHandler.handle(self)
  File "/usr/lib/python3.6/http/server.py", line 418, in handle
    self.handle_one_request()
  File "/usr/lib/python3/dist-packages/paste/httpserver.py", line 454, in handle_one_request
    self.wsgi_execute()
  File "/usr/lib/python3/dist-packages/paste/httpserver.py", line 307, in wsgi_execute
    self.wsgi_write_chunk(chunk)
  File "/usr/lib/python3/dist-packages/paste/httpserver.py", line 167, in wsgi_write_chunk
    self.wfile.write(chunk)
  File "/usr/lib/python3.6/socketserver.py", line 803, in write
    self._sock.sendall(b)
TypeError: a bytes-like object is required, not 'str'
----------------------------------------
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 33918)
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/paste/httpserver.py", line 1085, in process_request_in_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 364, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.6/socketserver.py", line 724, in __init__
    self.handle()
  File "/usr/lib/python3/dist-packages/paste/httpserver.py", line 459, in handle
    BaseHTTPRequestHandler.handle(self)
  File "/usr/lib/python3.6/http/server.py", line 418, in handle
    self.handle_one_request()
  File "/usr/lib/python3/dist-packages/paste/httpserver.py", line 454, in handle_one_request
    self.wsgi_execute()
  File "/usr/lib/python3/dist-packages/paste/httpserver.py", line 307, in wsgi_execute
    self.wsgi_write_chunk(chunk)
  File "/usr/lib/python3/dist-packages/paste/httpserver.py", line 167, in wsgi_write_chunk
    self.wfile.write(chunk)
  File "/usr/lib/python3.6/socketserver.py", line 803, in write
    self._sock.sendall(b)
TypeError: a bytes-like object is required, not 'str'
----------------------------------------

although netstat reports that thawab-gtk is listening to port 18080.

@aelmahmoudy
Copy link
Contributor Author

I modified baseWebApp.py (again) in okasha as follows:

   return (("Redirect to "+ str(e.kw['location'])).encode('utf-8'),) 

So the exception occurs only once.

@aelmahmoudy
Copy link
Contributor Author

@muayyad-alsadi I am stuck here. Please help

@aelmahmoudy
Copy link
Contributor Author

Please try to fix this as soon as possible.

@michele-musa
Copy link

Thawab doesn't open in Ubuntu 20.04.
Importing 'escape' from cgi fails under python3.8
at line 25 of Thawab/webApp.py

@aelmahmoudy
Copy link
Contributor Author

@ehabsas I see you've been working on this issue, is it fixed yet ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants