Python Http Error 500
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta
Httperror: Http Error 500: Internal Server Error
Discuss the workings and policies of this site About Us Learn more python urllib2.urlopen error 500 about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack
Python Httperror Exception
Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, urllib2 httperror helping each other. Join them; it only takes a minute: Sign up Overriding urllib2.HTTPError or urllib.error.HTTPError and reading response HTML anyway up vote 68 down vote favorite 18 I receive a 'HTTP Error 500: Internal Server Error' response, but I still want to read the data inside the error HTML. With Python 2.6, I normally fetch a page urllib python 3 using: import urllib2 url = "http://google.com" data = urllib2.urlopen(url) data = data.read() When attempting to use this on the failing URL, I get the exception urllib2.HTTPError: urllib2.HTTPError: HTTP Error 500: Internal Server Error How can I fetch such error pages (with or without urllib2), all while they are returning Internal Server Errors? Note that with Python 3, the corresponding exception is urllib.error.HTTPError. python urllib2 urllib http-error share|improve this question edited Oct 7 at 4:36 A-B-B 8,35033331 asked Feb 10 '10 at 0:55 Backus 74621227 add a comment| 3 Answers 3 active oldest votes up vote 131 down vote accepted The HTTPError is a file-like object. You can catch it and then read its contents. try: resp = urllib2.urlopen(url) contents = resp.read() except urllib2.HTTPError, error: contents = error.read() share|improve this answer answered Feb 10 '10 at 1:18 Joe Holloway 15.5k125881 2 Once we have done error.read(), error.read() subsequently returns empty string. Sometimes this messes up code elsewhere. How can we politely put the contents of the error back for o
here for a quick overview of the site Help Center
Python Requests
Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss http://stackoverflow.com/questions/2233687/overriding-urllib2-httperror-or-urllib-error-httperror-and-reading-response-html Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Traceback when I use urllib2, get a HTTP 500 error up vote 1 down vote favorite My code is http://stackoverflow.com/questions/14020784/traceback-when-i-use-urllib2-get-a-http-500-error like follows, but when it runs it throws an error. search_request = urllib2.Request(url,data=tmp_file_name,headers={'X-Requested-With':'WoMenShi888XMLHttpRequestWin'}) #print search_request.get_method() search_response = urllib2.urlopen(search_request) html_data = search_response.read() the error is: Traceback (most recent call last): File "xx_tmp.py", line 83, in
with a mandatory word, e.g. keyword2 keyword1 +keyword2 Questions excluding a word, e.g. keyword2 keyword1 -keyword2 Questions with a specific tag and keyword(s) https://developer.ibm.com/answers/questions/172922/python-call-watson-question-and-answer-always-get.html +[tag1] keyword1 Questions with two or more specific tags and keyword(s) +[tag1] +[tag2] keyword1 To search for all posts by a user or all posts with a specific tag, https://www.zabbix.com/forum/showthread.php?t=42828 start typing and choose from the suggestion list. Tags Spaces API Connect Appsecdev BPM Blockchain Bluemix CICS Cloud Analytics Cloud marketplace Content Services (ECM) Continuous Testing Courses DB2 error 500 LUW DataPower Decision Optimization DevOps Services Digital Experience Hadoop IBM Design IIDR ITOA InformationServer Integration Bus Internet of Things LinuxONE MDM Mainframe Messaging Node.js ODM Open Predictive Analytics PureData for Analytics Push Run Book Automation Storage Streamsdev Swift UrbanCode WASdev WSRR Watson dW Answers Help dW Premium developerWorks Team Watson Health More Users Badges Ask a http error 500 question python call Watson Question and Answer always get HTTP 500 error. not sure why... Question by DonnieGou ( 18) | Jan 29, 2015 at 11:26 PM pythonwatson question and aurllib2 import os import urllib import urllib2 import json import base64 questiontext = 'what caused hurt?' qaa_url = 'https://watson.ihost.com/instance/67/deepqa/v1/question' qaa_username = 'wat3_approver3' qaa_password = 'hF5EFmqZ' question_sub_dict = {} question_sub_dict['questionText'] = questiontext question_dict = {} question_dict['question'] = question_sub_dict question_json = json.dumps(question_dict) auth ='Basic ' + base64.b64encode( qaa_username+':'+ qaa_password ) #try urllib2 passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() passmgr.add_password(None,qaa_url,qaa_username,qaa_password) urllib2.install_opener(urllib2.build_opener(urllib2.HTTPBasicAuthHandler(passmgr))) req = urllib2.Request(qaa_url,params) req.add_header('Accept', 'application/json') req.add_header('X-SyncTimeout','30') req.add_header('Authorization',auth) f = urllib2.urlopen(req) res = f.read() it always get below error: C:\Python27\DONNIE_CODE\Py-Blue-demo>python localtest.py Traceback (most recent call last): File "localtest.py", line 56, in
Pictures & Albums Members List Search Forums Show Threads Show Posts Tag Search Advanced Search Go to Page... Thread Tools Display Modes #1 22-10-2013, 17:35 theKashyap Junior Member Join Date: Sep 2013 Posts: 4 Python get() API giving "internal server error" for 10000+ items Hey Guys, I've written the following piece of python code to fetch the list of items for a given host. It works for hostAAA and hostBBB, which have ~80 and ~4000 items respectively. But it consistently fails for hostCCC which has about 10000 items. Error is always the same: "urllib2.HTTPError: HTTP Error 500: Internal Server Error" Any ideas? Workarounds are welcome too as long as I can get the list in python.. I believe I'm using this python port of the API. Code: import sys import zabbix_api import logging import csv if __name__ != '__main__': print 'Run from command line. Do not import.' sys.exit(1) # Connect... ZABBIX_USERNAME, ZABBIX_PASSWORD, zabbixServer = 'admin', 'password', 'zabbix.dev.com' zapi = zabbix_api.ZabbixAPI(server="http://%s/zabbix/" % zabbixServer) zapi.login(ZABBIX_USERNAME, ZABBIX_PASSWORD) def getItems(host): # get the hostId from hostName hostId = zapi.host.get({"filter": {"host": host}})[0]["hostid"] return zapi.item.getObjects({'hostid': hostId}) def getItemsForHost(host): items = getItems(host) with open(host + '_items.csv', 'wb') as csvFile: # we're interested only in these fields for our analysis. fieldNames = ['hostid', 'itemid', 'name', 'type', 'key_', 'templateid', 'status', 'description'] out = csv.DictWriter(csvFile, fieldNames, extrasaction='ignore') out.writeheader() for item in items: out.writerow(item) getItemsForHost('hostAAA') # around 78 items getItemsForHost('hostBBB') # around 3800 items getItemsForHost('hostCCC') # 10000+ items Code: Traceback (most recent call last): File "C:\Workspaces\eclipse-kepler\ZabbixConfig\zabbixClient.py", line 64, in