Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how do i fix this invalid arguement error

697 views
Skip to first unread message

junk...@gmail.com

unread,
Nov 26, 2016, 11:13:00 AM11/26/16
to
import csv
with open('\\192.168.0.1\fe18cb0618cabd41\ninjatrader$EURUSDTestRun 2016-11-25-11-11.csv','r') as f:
reader=csv.reader(f)
for row in reader:
print(row)


File "C:/Users/Suresh/PycharmProjects/untitled/test.py", line 2, in <module>
with open('\\192.168.0.1\fe18cb0618cabd41\ninjatrader$EURUSDTestRun 2016-11-25-11-11.csv','r') as f:
OSError: [Errno 22] Invalid argument: '\\192.168.0.1\x0ce18cb0618cabd41\ninjatrader$EURUSDTestRun 2016-11-25-11-11.csv'

Terry Reedy

unread,
Nov 26, 2016, 2:18:55 PM11/26/16
to
On 11/26/2016 12:55 PM, Dennis Lee Bieber wrote:
> On Sat, 26 Nov 2016 08:12:46 -0800 (PST), junk...@gmail.com declaimed the
> following:
> First suggestion... Make it a RAW string. What you have has an embedded
> new-line character making it:
> \\192.168.0.1\fe18cb0618cabd41
> injatrader$EURUSDTestRun 2016-11-25-11-11.csv

Or use forward slashes:
with open('/192.168.0.1/fe18cb0618cabd41/ninjatrader$EURUSDTestRun
2016-11-25-11-11.csv','r') as f:

> Second... does Python open() accept web addresses? What is at
> 192.168.0.1 that you don't have some more sensible path to it? 192.168.0.1
> is a private local network address. You are on a Windows machine so if the
> file is available on a local network node you can probably mount that node
> (Computer/Map Network Drive) and access the file as something like
> Z:/ninjatrader...
>


--
Terry Jan Reedy

Steve D'Aprano

unread,
Nov 26, 2016, 7:07:09 PM11/26/16
to
On Sun, 27 Nov 2016 03:12 am, junk...@gmail.com wrote:

> import csv
> with open('\\192.168.0.1\fe18cb0618cabd41\ninjatrader$EURUSDTestRun
> 2016-11-25-11-11.csv','r') as f:

\f inserts a FORMFEED character, ASCII code 12. \n inserts a LINEFEED
character, or newline, ASCII code 10. I believe that on Windows, both are
illegal in file names. And \\ inserts a single backslash.

You have three solutions:

(1) Use forward slashes, which Windows accepts as well:

'//192.168.0.1/fe18cb0618cabd41/ninjatrader$EURUSDTestRun
2016-11-25-11-11.csv'


(2) Use a "raw string" to disable most (but not all) backslash escapes:

r'\\192.168.0.1\fe18cb0618cabd41\ninjatrader$EURUSDTestRun
2016-11-25-11-11.csv'


The problem with raw strings is that you cannot end a string with a
backslash, so you cannot write:

# this gives a syntax error
r'C:\My Documents\directory\'


(3) Or escape all your backslashes with more backslashes:

'\\\\192.168.0.1\\fe18cb0618cabd41\\ninjatrader$EURUSDTestRun
2016-11-25-11-11.csv'




--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

Cameron Simpson

unread,
Nov 26, 2016, 9:56:30 PM11/26/16
to
On 26Nov2016 12:55, Dennis Lee Bieber <wlf...@ix.netcom.com> wrote:
>On Sat, 26 Nov 2016 08:12:46 -0800 (PST), junk...@gmail.com declaimed the
>following:
>> with open('\\192.168.0.1\fe18cb0618cabd41\ninjatrader$EURUSDTestRun 2016-11-25-11-11.csv','r') as f:
[...]
> Second... does Python open() accept web addresses? What is at
>192.168.0.1 that you don't have some more sensible path to it? 192.168.0.1
>is a private local network address. You are on a Windows machine so if the
>file is available on a local network node you can probably mount that node
>(Computer/Map Network Drive) and access the file as something like
>Z:/ninjatrader...

I thought //192.168.0.1/foo/... was a network share, getting "foo" from host
192.168.0.1. Disclaimer: not a Windows guy. But I've certainly using UNIXy
systems implementing this syntax, and thought I'd seen an equivalent in Windows
land. So not HTTP, SMB. Confirmation or refutation from anyone?

Cheers,
Cameron Simpson <c...@zip.com.au>

Chris Angelico

unread,
Nov 26, 2016, 9:59:57 PM11/26/16
to
On Sun, Nov 27, 2016 at 1:24 PM, Cameron Simpson <c...@zip.com.au> wrote:
> I thought //192.168.0.1/foo/... was a network share, getting "foo" from host
> 192.168.0.1. Disclaimer: not a Windows guy. But I've certainly using UNIXy
> systems implementing this syntax, and thought I'd seen an equivalent in
> Windows land. So not HTTP, SMB. Confirmation or refutation from anyone?

Confirmed, that's the NETBIOS-over-TCP syntax, which Microsoft has
maintained into the newer Windows drive-sharing protocols.

ChrisA

eryk sun

unread,
Nov 27, 2016, 10:00:31 AM11/27/16
to
On Sat, Nov 26, 2016 at 5:55 PM, Dennis Lee Bieber
<wlf...@ix.netcom.com> wrote:
> On Sat, 26 Nov 2016 08:12:46 -0800 (PST), junk...@gmail.com declaimed the
> following:
>
>> with open('\\192.168.0.1\fe18cb0618cabd41\ninjatrader$EURUSDTestRun
>> 2016-11-25-11-11.csv','r') as f:
>
> Second... does Python open() accept web addresses? What is at
> 192.168.0.1 that you don't have some more sensible path to it? 192.168.0.1
> is a private local network address. You are on a Windows machine so if the
> file is available on a local network node you can probably mount that node
> (Computer/Map Network Drive) and access the file as something like
> Z:/ninjatrader...

r"\\192.168.0.1\fe18..." is a UNC (Universal Naming Convention) path,
as defined by [MS-DTYP], Windows Data Types [1].

[1]: https://msdn.microsoft.com/en-us/library/gg465305

On Windows, open() calls CreateFile, which first translates DOS paths
to native paths that the kernel understands. UNC paths are converted
to the form r"\??\UNC\<Server>\<Share>\<Path>".

In kernel mode, the object manager resolves the virtual r"\??"
directory by checking for a "UNC" object in either the logon-session
DosDevices directory of the calling process/thread or the r"\GLOBAL??"
directory. r"\??\UNC" should almost always resolve to
r"\GLOBAL??\UNC". This is an object symbolic link to the native MUP
device (Multiple UNC Provider) [2], so the final path is
r"\Device\Mup\<Server>\<Share>\<Path>".

[2]: https://msdn.microsoft.com/en-us/library/ff556761

MUP resolves the <Server>\<Share> prefix to a registered provider
device, such as LanmanRedirector (SMB/CIFS), MailslotRedirector,
WebDavRedirector, RdpDr (RDP device redirector), or Csc (client-side
caching / offline files). If you're running Windows as a VirtualBox
guest, then your system may also have a VboxMiniRdr provider for
accessing folders shared by the host OS.

As to mount points, for many years Windows has provided flexible
alternatives to classic drive-letter (i.e. logical) mount points. I
prefer to mount UNC paths as symbolic links via `mklink /d` and local
volumes as junctions via `mountvol`.
0 new messages