WebFaction
Community site: login faq

I'm trying to load a file from my own server into a piece of code. I've done similar things several times elsewhere in the code, but always from external sites in the past.

The file is at http://mydomain.com/static/data/somefile.csv - this file works, and if I navigate to it in the browser, it downloads the file.

In my app I'm using master_data = open (r'http://mydomain.com/static/data/somefile.csv', 'r'), and getting:

Exception Type: IOError Exception Value:
[Errno 2] No such file or directory:

asked 24 Apr '14, 05:39

iamwithnail
11
accept rate: 0%


You cannot open a URL with Python's open() function. When you attempt to do so, Python is trying to open a local file named "http://mydomain.com/static/data/somefile.csv", so of course that fails.

Instead, use urllib2.urlopen(), eg:

import urllib2
master_data = urllib2.urlopen(r'http://mydomain.com/static/data/somefile.csv')

Hope that helps!

permanent link

answered 24 Apr '14, 18:21

seanf
12.2k31836
accept rate: 37%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×904
×337
×124

question asked: 24 Apr '14, 05:39

question was seen: 1,610 times

last updated: 24 Apr '14, 18:21

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM