nahamsec / JSParser

783 stars 178 forks source link

Python 3.x support (ImportError: No module named 'StringIO') #18

Open 0xdevalias opened 6 years ago

0xdevalias commented 6 years ago

When running python handler.py I get the following error:

ImportError: No module named 'StringIO'

I believe this is related to python 3.x

⇒  python --version
Python 3.5.2
gopinath6 commented 6 years ago

May i know any fix available for this?

EdOverflow commented 6 years ago

Use the following:

try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO
gopinath6 commented 6 years ago

Thanks.After above fix got below error

image

EdOverflow commented 6 years ago

urlparse was renamed to urllib.parse in Python 3.

gopinath6 commented 6 years ago

@EdOverflow Thanks a lot . it worked.

Sechunt3r commented 5 years ago

When running python3 handler.py I get the following error:

ModuleNotFoundError: No module named 'StringIO'

I already added this following code in my handler.py and also i changed the urlparse to urllib.parse!

Thanks for advance @EdOverflow

EdOverflow commented 5 years ago

Have you tried just using from io import StringIO, @Sechunt3r?

Sicks3c commented 5 years ago

@EdOverflow python3 handler.py works fine but when I parse urls in the localhostm I get this error

  File "/usr/lib/python3/dist-packages/tornado/web.py", line 1590, in _execute
    result = method(*self.path_args, **self.path_kwargs)
  File "handler.py", line 198, in post
    data = self.parseLinks(url, headers)
  File "handler.py", line 184, in parseLinks
    file = self.fetchURL(url, headers)
  File "handler.py", line 179, in fetchURL
    res = sc.execute(url)
  File "/opt/JSParser/safeurl.py", line 710, in execute
    response = StringIO.StringIO()
AttributeError: type object '_io.StringIO' has no attribute 'StringIO'
ERROR:tornado.access:500 POST /parse/ajax (::1) 73.78ms
kunal812eee commented 5 years ago

hey anyone can help me in these errors. ss attached

Screenshot from 2019-08-06 18-13-08

Sicks3c commented 5 years ago

@kunal812eee replace import StringIO to from io import StringIO

pentestweb1337 commented 5 years ago

root@local:~/JSParser$ python3 handler.py Traceback (most recent call last): File "handler.py", line 5, in import safeurl, types, sys, re, mimetypes, glob, jsbeautifier, urlparse, pycurl ModuleNotFoundError: No module named 'urlparse'

Guneetkaur03 commented 4 years ago

Use the following:

try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO

Thanks it worked

undefined-rahulraj commented 4 years ago

@EdOverflow python3 handler.py works fine but when I parse urls in the localhostm I get this error

  File "/usr/lib/python3/dist-packages/tornado/web.py", line 1590, in _execute
    result = method(*self.path_args, **self.path_kwargs)
  File "handler.py", line 198, in post
    data = self.parseLinks(url, headers)
  File "handler.py", line 184, in parseLinks
    file = self.fetchURL(url, headers)
  File "handler.py", line 179, in fetchURL
    res = sc.execute(url)
  File "/opt/JSParser/safeurl.py", line 710, in execute
    response = StringIO.StringIO()
AttributeError: type object '_io.StringIO' has no attribute 'StringIO'
ERROR:tornado.access:500 POST /parse/ajax (::1) 73.78ms

Did you find any solution for this one ?

sec000 commented 4 years ago

@EdOverflow python3 handler.py works fine but when I parse urls in the localhostm I get this error

  File "/usr/lib/python3/dist-packages/tornado/web.py", line 1590, in _execute
    result = method(*self.path_args, **self.path_kwargs)
  File "handler.py", line 198, in post
    data = self.parseLinks(url, headers)
  File "handler.py", line 184, in parseLinks
    file = self.fetchURL(url, headers)
  File "handler.py", line 179, in fetchURL
    res = sc.execute(url)
  File "/opt/JSParser/safeurl.py", line 710, in execute
    response = StringIO.StringIO()
AttributeError: type object '_io.StringIO' has no attribute 'StringIO'
ERROR:tornado.access:500 POST /parse/ajax (::1) 73.78ms

Did you find any solution for this one ?

Edit both files ( handler.py and safeurl.py) from io import StringIO

kahwekjrhkasdhfasg commented 4 years ago

@EdOverflow python3 handler.py works fine but when I parse urls in the localhostm I get this error

  File "/usr/lib/python3/dist-packages/tornado/web.py", line 1590, in _execute
    result = method(*self.path_args, **self.path_kwargs)
  File "handler.py", line 198, in post
    data = self.parseLinks(url, headers)
  File "handler.py", line 184, in parseLinks
    file = self.fetchURL(url, headers)
  File "handler.py", line 179, in fetchURL
    res = sc.execute(url)
  File "/opt/JSParser/safeurl.py", line 710, in execute
    response = StringIO.StringIO()
AttributeError: type object '_io.StringIO' has no attribute 'StringIO'
ERROR:tornado.access:500 POST /parse/ajax (::1) 73.78ms

Did you find any solution for this one ?

In python 3.7, I edit safeurl.py as following and it work

  1. import io
  2. edit line No.710 response = StringIO.StringIO() to response = io.BytesIO()
  3. edit line No.732 return response.getvalue() to return response.getvalue().decode('utf-8')
attacker34 commented 4 years ago

Use the following:

try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO

Hi @EdOverflow Can You please let me know where to paste this snippet?

Thanks.

shikhayadav2481996 commented 4 years ago

Have you tried just using from io import StringIO, @Sechunt3r?

I tried from io import StringIO this also then also I am getting error in installing StingIO and I am getting this error while installing StringIO , ERROR: Could not find a version that satisfies the requirement StringIO (from versions: none) ERROR: No matching distribution found for StringIO

can any one help me in installing StingIO

sailfish009 commented 4 years ago

you could use StringIO, but most case BytesIO is correct solution.

ikish0re commented 3 years ago

Traceback (most recent call last): File "handler.py", line 250, in application.listen(portNum) File "/usr/lib/python3/dist-packages/tornado/web.py", line 2042, in listen server.listen(port, address) File "/usr/lib/python3/dist-packages/tornado/tcpserver.py", line 143, in listen sockets = bind_sockets(port, address=address) File "/usr/lib/python3/dist-packages/tornado/netutil.py", line 168, in bind_sockets sock.bind(sockaddr) OSError: [Errno 98] Address already in use

Anyone help me to fix this error

Im getting this type of error

zy9ard3 commented 3 years ago

Have you tried just using from io import StringIO, @Sechunt3r ?

I tried from io import StringIO this also then also I am getting error in installing StingIO and I am getting this error while installing StringIO , ERROR: Could not find a version that satisfies the requirement StringIO (from versions: none) ERROR: No matching distribution found for StringIO

can any one help me in installing StingIO

use pip3 install -r requirements.txt

Crj777 commented 3 years ago

Edit safeurl.py and give try: from StringIO import StringIO except ImportError: from io import StringIO Then edit handler.py and in line 5 replace urlparse with urllib.parse Then replace cgi with html i.e from html import escape This will solve the issue thanks😊

ShudarsanRegmi commented 3 years ago

I got the following error: image

JosephGregg commented 2 years ago

@ShudarsanRegmi Literally what @Crj777 said. Replace "from cgi import escape" with "from html import scape"

prabeshram commented 1 year ago

while running python handler.py i get this issue

Traceback (most recent call last): File "/home/kalki/Desktop/bug_bounty/JSParser/handler.py", line 5, in import safeurl, types, sys, re, mimetypes, glob, jsbeautifier, urlparse, pycurl File "/home/kalki/Desktop/bug_bounty/JSParser/safeurl.py", line 18, in import StringIO ModuleNotFoundError: No module named 'StringIO'

How can i fix this?

weisisheng commented 1 year ago

+1

sushantvishu commented 1 year ago

<iframe+src=x+onload=prompt(1)>