[Tutor] (no subject)

Andrew P grouch at gmail.com
Mon Oct 31 17:28:40 CET 2005


Before you hit the debugger, it might be a good idea to just run the
script normally, either at the command line, or inside IDLE/Pythonwin.

Doing so will spit out:

Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
NameError: name 'ftplib' is not defined

Because you imported with:

from ftplib import FTP"

you don't need to prepend the module name before you call FTP.  If you
do "import ftplib" instead, then it will work.  Conversely, if you
call with just "FTP("ftp.website.com") it will also work.

 It's really a personal choice which you do, but the second choice is
safer, as it has no chance of polluting your module's namespace if you
accidentally call something FTP.

Also, I noticed when pasting into IDLE that you have mismatched quotes:

ftp.login('user', 'pwd') # user, passwd

Using IDLE/Pythonwin will catch problems like that.

Good luck,

Andrew

On 10/31/05, Roberts, Alice <ARoberts at ambac.com> wrote:
>
>
>
> Good morning,
>
>
>
> I'm migrating from DOS scripting to Python, and need a little help.  I got
> this sample from a Google search that brought me to effbot.org,
> http://effbot.org/librarybook/ftplib.htm.  Also, I plugged
> in all my variables when I tested, but replaced with generics for this
> email. ie) ftp.website.com.
>
>
>
> Thank you,
>
>
>
> Alice Roberts
>
> Ambac Assurance Corp.
>
>
>
> from ftplib import FTP
>
> import sys
>
>
>
> def upload(ftp, file):
>
>         ftp.storlines("STOR " + file, open(file))
>
>
>
> ftp = ftplib.FTP('ftp.website.com')   # connect to host, default port
>
> ftp.login('user', 'pwd') # user, passwd
>
> ftp.set_debuglevel(1)
>
> ftp.cwd('/temp')
>
> ftp.delete('fname.txt')
>
>
>
> upload(ftp, "fname.txt")
>
>
>
> ftp.quit()
>
> ftp.close()
>
>
>
> When I ran in debugger, calling the FTP library invokes a no SOCKS module
> error that the ftplib seems to be trying to access.
>
>
>
> >>> --Call--
>
> >>> Unhandled exception while debugging...
>
> Traceback (most recent call last):
>
>   File "C:\Python24\lib\ftplib.py", line 42, in ?
>
>     import SOCKS; socket = SOCKS; del SOCKS # import SOCKS as socket
>
> ImportError: No module named SOCKS
>
> >>> --Call--
>
> >>> Unhandled exception while debugging...
>
> Traceback (most recent call last):
>
>   File "C:\Python24\lib\socket.py", line 50, in ?
>
>     import _ssl
>
> ImportError: No module named _ssl
>
> >>> --Call--
>
> >>> Unhandled exception while debugging...
>
> Traceback (most recent call last):
>
>   File "C:\Python24\lib\os.py", line 36, in _get_exports_list
>
>     return list(module.__all__)
>
> AttributeError: 'module' object has no attribute '__all__'
>
> [Dbg]>>> Traceback (most recent call last):
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
> line 305, in RunScript
>
>     debugger.run(codeObject, __main__.__dict__, start_stepping=1)
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\__init__.py",
> line 60, in run
>
>     _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\debugger.py",
> line 595, in run
>
>     exec cmd in globals, locals
>
>   File "c:\temp\ftp_get_hub.py", line 13, in ?
>
>     ftp = ftplib.FTP("ftp.website.com")   # connect to host, default port
>
> NameError: name 'ftplib' is not defined
>
> [Dbg]>>> Traceback (most recent call last):
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
> line 305, in RunScript
>
>     debugger.run(codeObject, __main__.__dict__, start_stepping=1)
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\__init__.py",
> line 60, in run
>
>     _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\debugger.py",
> line 595, in run
>
>     exec cmd in globals, locals
>
>   File "c:\temp\ftp_put_hub.py", line 3, in ?
>
>     import FTP
>
> ImportError: No module named FTP
>
> [Dbg]>>> Traceback (most recent call last):
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
> line 305, in RunScript
>
>     debugger.run(codeObject, __main__.__dict__, start_stepping=1)
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\__init__.py",
> line 60, in run
>
>     _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\debugger.py",
> line 595, in run
>
>     exec cmd in globals, locals
>
>   File "c:\temp\ftp_put_hub.py", line 9, in ?
>
>     ftp = ftplib.FTP('ftp.website.com')   # connect to host, default port
>
> NameError: name 'ftplib' is not defined
>
> [Dbg]>>>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>


More information about the Tutor mailing list