<p>Is there a way to make psycopg and postgres deal with errors without having to reestablish the connection, like MySQLdb?  The commented version of the below works with MySQLdb, the comments make it work with Psycopg2:</p>

<pre><code>results = {'felicitas': 3, 'volumes': 8, 'acillevs': 1, 'mosaics': 13, 'perat\xe9': 1, 'representative': 6....}
for item in sorted(results):
    try:
        cur.execute("""insert into resultstab values ('%s', %d)""" % (item, results[item]))
        print item, results[item]
#       conn.commit()
    except:
#       conn=psycopg2.connect(user='bvm', database='wdb', password='redacted')
#       cur=conn.cursor()
        print 'choked on', item
        continue
</code></pre>

<p>This must slow things down, could anyone give a suggestion for passing over formatting errors?  Obviously the above chokes on apostrophes, but is there a way to make it pass over that without getting something like the following, or committing, reconnecting, etc?:</p>

<pre><code>agreement 19
agreements 1
agrees 1
agrippa 9
choked on agrippa's
choked on agrippina
</code></pre>

[{'answer_id': 70692, 'author': 'Roger Lipscombe', 'author_id': 8446, 'author_profile': 'https://Stackoverflow.com/users/8446', 'pm_score': 0, 'selected': False, 'text': '<p>If I recall correctly, VMWare Server has a scripting interface, available via Perl or COM. You might be able to use that to automatically pause the VMs before running the backup.</p>\n\n<p>If your backup software was shadow-copy aware, that might work, too.</p>\n'}, {'answer_id': 70740, 'author': 'John Stauffer', 'author_id': 5874, 'author_profile': 'https://Stackoverflow.com/users/5874', 'pm_score': 4, 'selected': True, 'text': '<p>VMWare server includes the command line tool "vmware-cmd", which can be used to perform virtually any operation that can be performed through the console.</p>\n\n<p>In this case you would simply add a "vmware-cmd  susepend" to your script before starting your backup, and a "vmware-cmd  start" after the backup is completed.</p>\n\n<p>We use vmware-server as part of our  build system to provide a known environment to run automated DB upgrades against, so we end up rolling back state as part of each build (driven by CruiseControl), and have found this interface to be rock solid.</p>\n\n<pre><code>Usage: /usr/bin/vmware-cmd &lt;options&gt; &lt;vm-cfg-path&gt; &lt;vm-action&gt; &lt;arguments&gt;\n       /usr/bin/vmware-cmd -s &lt;options&gt; &lt;server-action&gt; &lt;arguments&gt;\n\n  Options:\n    Connection Options:\n       -H &lt;host&gt;       specifies an alternative host (if set, -U and -P must also be set)\n       -O &lt;port&gt;       specifies an alternative port\n       -U &lt;username&gt;   specifies a user\n       -P &lt;password&gt;   specifies a password\n    General Options:\n       -h More detailed help.\n       -q Quiet. Minimal output\n       -v Verbose.\n\n  Server Operations:\n    /usr/bin/vmware-cmd -l \n    /usr/bin/vmware-cmd -s register &lt;config_file_path&gt;\n    /usr/bin/vmware-cmd -s unregister &lt;config_file_path&gt;\n    /usr/bin/vmware-cmd -s getresource &lt;variable&gt;\n    /usr/bin/vmware-cmd -s setresource &lt;variable&gt; &lt;value&gt;\n\n  VM Operations:\n    /usr/bin/vmware-cmd &lt;cfg&gt; getconnectedusers\n    /usr/bin/vmware-cmd &lt;cfg&gt; getstate\n    /usr/bin/vmware-cmd &lt;cfg&gt; start &lt;powerop_mode&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; stop &lt;powerop_mode&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; reset &lt;powerop_mode&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; suspend &lt;powerop_mode&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; setconfig &lt;variable&gt; &lt;value&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; getconfig &lt;variable&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; setguestinfo &lt;variable&gt; &lt;value&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; getguestinfo &lt;variable&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; getid\n    /usr/bin/vmware-cmd &lt;cfg&gt; getpid\n    /usr/bin/vmware-cmd &lt;cfg&gt; getproductinfo &lt;prodinfo&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; connectdevice &lt;device_name&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; disconnectdevice &lt;device_name&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; getconfigfile\n    /usr/bin/vmware-cmd &lt;cfg&gt; getheartbeat\n    /usr/bin/vmware-cmd &lt;cfg&gt; getuptime\n    /usr/bin/vmware-cmd &lt;cfg&gt; getremoteconnections\n    /usr/bin/vmware-cmd &lt;cfg&gt; gettoolslastactive\n    /usr/bin/vmware-cmd &lt;cfg&gt; getresource &lt;variable&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; setresource &lt;variable&gt; &lt;value&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; setrunasuser &lt;username&gt; &lt;password&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; getrunasuser\n    /usr/bin/vmware-cmd &lt;cfg&gt; getcapabilities\n    /usr/bin/vmware-cmd &lt;cfg&gt; addredo &lt;disk_device_name&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; commit &lt;disk_device_name&gt; &lt;level&gt; &lt;freeze&gt; &lt;wait&gt;\n    /usr/bin/vmware-cmd &lt;cfg&gt; answer\n</code></pre>\n'}, {'answer_id': 129123, 'author': 'seisyll', 'author_id': 21815, 'author_profile': 'https://Stackoverflow.com/users/21815', 'pm_score': 0, 'selected': False, 'text': '<p>There is a tool called (ahem) Hobocopy which will copy locked VM files.  I would recommend  taking a snapshot of the VM and then backing up the VMDK.  Then merge the snapshot after the copy is complete. </p>\n'}, {'answer_id': 551985, 'author': 'Martin Beckett', 'author_id': 10897, 'author_profile': 'https://Stackoverflow.com/users/10897', 'pm_score': 2, 'selected': False, 'text': '<p>Worth looking at rsync? If only part of a large image file is changing then rsync might be the fastest way to copy any changes.</p>\n'}, {'answer_id': 2129965, 'author': 'MadCAt', 'author_id': 258119, 'author_profile': 'https://Stackoverflow.com/users/258119', 'pm_score': 1, 'selected': False, 'text': '<p>I found an easy to follow guide for backing up VM\'s in vmware server 2 here: <a href="http://www.bdts.com.au/tips/46-vmware/57-backing-up-vmware-server-2-.html" rel="nofollow noreferrer">Backup VMware Server 2</a></p>\n'}]
['https://Stackoverflow.com/questions/70681', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11596/']