Table Of Contents

Previous topic

psychopy.voicekey - Real-time sound processing

Next topic

Troubleshooting

This Page

Quick links

psychopy.web - Web methods

Test for access

psychopy.web.haveInternetAccess(forceCheck=False)

Detect active internet connection or fail quickly.

If forceCheck is False, will rely on a cached value if possible.

psychopy.web.requireInternetAccess(forceCheck=False)

Checks for access to the internet, raise error if no access.

Upload a file over http

psychopy.web.upload(selector, filename, basicAuth=None, host=None, https=False, log=True)

DEPRECATED: Upload a local file over the internet to a configured http server. Use the requests package instead. See http://www.python-requests.org/

This method handshakes with a php script on a remote server to transfer a local file to another machine via http (using POST).

Returns “success” plus a sha256 digest of the file on the server and a byte count. If the upload was not successful, an error code is returned (eg, “too_large” if the file size exceeds the limit specified server-side in up.php, or “no_file” if there was no POST attachment).

Note

The server that receives the files needs to be configured before uploading will work. php files and notes for a sys-admin are included in psychopy/contrib/http/. In particular, the php script up.php needs to be copied to the server’s web-space, with appropriate permissions and directories, including apache basic auth and https (if desired). The maximum size for an upload can be configured within up.php

Parameters:

selector
: (required, string)

a standard URL of the form http://host/path/to/up.php, e.g., http://upload.psychopy.org/test/up.php

Note

Limited https support is provided (see below).

filename
: (required, string)

the path to the local file to be transferred. The file can be any format: text, utf-8, binary. All files are hex encoded while in transit (increasing the effective file size).

Note

Encryption (beta) is available as a separate step. That is, first encrypt() the file, then upload() the encrypted file in the same way that you would any other file.

basicAuth
: (optional)
apache ‘user:password’ string for basic authentication. If a basicAuth value is supplied, it will be sent as the auth credentials (in cleartext); using https will encrypt the credentials.
host
: (optional)
The default process is to extract host information from the selector. The host option allows you to specify a host explicitly (i.e., if it differs from the selector).
https
: (optional)

If the remote server is configured to use https, passing the parameter https=True will encrypt the transmission including all data and basicAuth credentials. It is approximately as secure as using a self-signed X.509 certificate.

An important caveat is that the authenticity of the certificate returned from the server is not checked, and so the certificate could potentially be spoofed (see the warning under HTTPSConnection http://docs.python.org/library/httplib.html). Overall, using https can still be much more secure than not using it. The encryption is good, but that of itself does not eliminate all risk. Importantly, it is not as secure as one might expect, given that all major web browsers do check certificate authenticity. The idea behind this parameter is to require people to explicitly indicate that they want to proceed anyway, in effect saying “I know what I am doing and accept the risks (of using un-verified certificates)”.

Author: Jeremy R. Gray, 2012

Proxy set-up and testing

psychopy.web.setupProxy(log=True)

Set up the urllib proxy if possible.

The function will use the following methods in order to try and determine proxies:

  1. standard urllib.request.urlopen (which will use any statically-defined http-proxy settings)
  2. previous stored proxy address (in prefs)
  3. proxy.pac files if these have been added to system settings
  4. auto-detect proxy settings (WPAD technology)
Returns:True (success) or False (failure)