By adding two simple files in your home directory, you can access netCDF files with e.g. Python and Matlab via OPeNDAP without the need to put your credentials in the script.
The two required files are:
Note: the domain is the part of the url right behind http(s):// until the next / (see also the examples in the links mentioned below).
It's obvious that you should be conscious of the fact that the .netrc file contains your password in plain text. Don't do this on a public or shared PC.
See http://docs.opendap.org/index.php/DAP_Clients_-_Authentication for more information. The explanation above is in particular based on http://docs.opendap.org/index.php/DAP_Clients_-_Authentication#Matlab.2C_Ferret.2C_Other_applications_that_use_NetCDF_C