Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9054693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:45:12+00:00 2026-06-16T13:45:12+00:00

I have copied this code from the other SO question but i am not

  • 0

I have copied this code from the other SO question but i am not able to solve the error i am getting

this is my code

import os
import urllib2
import sys
d = urllib2.urlopen("http://www.google.com.au/logos/2012/new_years_eve_2012_-_english_only-1049005-hp.jpg")
o = open('image.%s' % d.info().gettype(), 'w')
o.write(d.read())

The error is

Traceback (most recent call last): File “./image_test.py”, line 6,
in
o = open(‘image.%s’ % d.info().gettype(), ‘w’) IOError: [Errno 2] No such file or directory: ‘image.image/jpeg’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:45:13+00:00Added an answer on June 16, 2026 at 1:45 pm

    This is because HTML MIME-types typically include slash, e.g. image/jpeg. That causes confusion for open, since slash is a special character used in file system routing.

    You just have to avoid slash in a file name, for example in a way Joran proposed.

    UPDATE In order to make it work in all situations, you have to get a map MIME-type -> file extension. There’s one at Apache: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=markup . Once you parse it to python dictionary like this:

    import re
    
    mimetypes = {}
    with open('mime.types') as mimedata:
        for line in [line.strip() for line in mimedata.readlines()]:
            if line[0] == '#':
                continue
    
            # This pattern will only get the first extension in the list
            pattern = re.compile(r'([^\s]+)\s+([^\s]+)')
            result  = pattern.match(line)
            mime    = result.group(1)
            ext     = result.group(2)
            mimetypes[mime] = ext
    

    you will use it the following way:

    mime = d.info().gettype()
    ext = ''
    if mime in mimetypes:
        ext = mimetypes[mime]
    
    o = open('data' + ext, 'w')
    o.write(d.read())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this sample code for async operations (copied from the interwebs) public class
I have this code copied from one of questions from SO: public static String
This code is taken from a previous question, but my question directly relates to
I copied this class from a similar class I have in this app that
This question comes from a range of other questions that all deal with essentially
I have copied some files across from one project to another. The code simply
why do I get this exception?please suggest any solutions.i have properly copied mail.jar and
I have copied class from net which inherits UIImageView. How to put that class
I have copied some files from project A to project B, both of which
I have copied zipped file from the playframework.org website and unzipped it at a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.