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

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

Open
0xdevalias opened this issue Nov 12, 2017 · 26 comments
Open

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

0xdevalias opened this issue Nov 12, 2017 · 26 comments

Comments

@0xdevalias
Copy link

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

May i know any fix available for this?

@EdOverflow
Copy link
Collaborator

Use the following:

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

@gopinath6
Copy link

Thanks.After above fix got below error

image

@EdOverflow
Copy link
Collaborator

urlparse was renamed to urllib.parse in Python 3.

@gopinath6
Copy link

@EdOverflow Thanks a lot . it worked.

@Sechunt3r
Copy link

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
Copy link
Collaborator

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

@Sicks3c
Copy link

Sicks3c commented Aug 1, 2019

@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
Copy link

hey anyone can help me in these errors.
ss attached

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

@Sicks3c
Copy link

Sicks3c commented Aug 6, 2019

@kunal812eee replace import StringIO to from io import StringIO

@pentestweb1337
Copy link

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

Use the following:

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

Thanks it worked

@undefined-rahulraj
Copy link

@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
Copy link

sec000 commented Mar 15, 2020

@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
Copy link

kahwekjrhkasdhfasg commented Mar 31, 2020

@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
Copy link

attacker34 commented Apr 10, 2020

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

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

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

@ikish0re
Copy link

ikish0re commented Dec 18, 2020

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

zy9ard3 commented Jul 16, 2021

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

Crj777 commented Jul 17, 2021

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

I got the following error:
image

@JosephGregg
Copy link

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

@prabeshram
Copy link

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

+1

@sushantvishu
Copy link

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

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