Posts

URLLib2.URL Error: Reading Server Response Codes (Python) -

i have list of urls. i'd see server response code of each , find out if broken. can read server errors (500) , broken links (404) okay, code breaks once non-website read (e.g. "notawebsite_broken.com"). i've searched around , not found answer... hope can help. here's code: import urllib2 #list of urls. third url not website urls = ["http://www.google.com","http://www.ebay.com/broken-link", "http://notawebsite_broken"] #empty list store output response_codes = [] # run "for" loop: server response code , save results response_codes url in urls: try: connection = urllib2.urlopen(url) response_codes.append(connection.getcode()) connection.close() print url, ' - ', connection.getcode() except urllib2.httperror, e: response_codes.append(e.getcode()) print url, ' - ', e.getcode() print response_codes this gives output of... http://www.google.com...

python - Accessing Django Modules from a Django subdirectory -

i'm setting documentation django project. documentation lives in folder called docs within project root: project-root/ doc/ app1/ app2/ app3/ urls/ the problem i'm writing extension documentation lives in doc/ folder. when generate documentation, run extension outside of context of django (just script). in extension, need access object in project's url's file. but when try import project.urls, import error. how can access project-root/urls when i'm running script in project-root/doc/extension.py isn't run through django? you can setup django environment this: import os, sys sys.path.append("/path/to/your_project/") os.environ["django_settings_module"] = "yourproject.settings"

spring - Url getting modified after request is received at the server -

i trying develop restful web service using spring framework apache tomcat. added 2 controller classes had 5-6 endpoints working fine. since yesterday when trying add endpoint getting strange error. @controller @requestmapping("/test") public class textcontroller { @requestmapping(method=requestmethod.post) public void test() { system.out.println("hello world"); } } when try url browser(using rest client) getting following output: hello world jun 25, 2014 7:05:55 pm org.springframework.web.servlet.pagenotfound nohandlerfound warning: no mapping found http request uri [/chitchatapp/rest/test/test] in dispatcherservlet name 'chitchat-dispatcher' the url showing "/test" appended. other apis still working fine. new ones adding giving error. my web.xml looks this: <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="...

java - How to mock a class throughout the system using Mockito -

i have method trying test using mockito: public class miscutil{ public int getvalue(string key){ properties properties = new helper().getproperties() //this method //i need mock return properties.get(key) } here test class : public class miscutiltest{ public void testgetbooleanvalue() { properties properties = new properties(); properties.setproperty(my_special_int_property, 10); // mock helper helper mock = mockito.mock(helper.class); // mock method getproperties() mockito.when(mock.getproperties()).thenreturn(properties); // assert getvalue() method assert.assertequals(10,miscutil.getvalue(my_special_int_property)); however, method doesn't mocked. have pass actual mocked instance miscutil class in order mocking take effect? miscutil class doesn't let me pass helper object it. easy mock particular method of class in jmockit though upper classes...

angularjs - Handling trailing slashes in angularUI router -

it's been hours since started working on problem , can't seem head around solution. i have app may result in users typing in url. in such cases not hard believe user might enter trailing slash. example, www.example.com/users/2 , www.example.com/edit/company/123 should treated same as www.example.com/users/2/ , www.example.com/edit/company/123/ this needs done handling url routing on client side. not interested in handling trailing slashes in resource/api calls. interested in handling trailing slashed in browser. so researched , found not many answers on net. of them led me faq section of angular-ui router. https://github.com/angular-ui/ui-router/wiki/frequently-asked-questions here tell write rule, want do, doesn't seem working, or maybe doing wrong. here's plunkr have added code. http://plnkr.co/edit/fd9q7l?p=preview i have added config, rest of code pretty basic stuff. $urlrouterprovider.rule(function($injector, $location) { /...

android - Getting error with SmackAndroid.init(context) -

Image
i trying create room using asmack muc. have connect() method connects xmpp server no problem (below). public void connect() { connectionconfiguration connconfig = new connectionconfiguration(host, port, service); xmppconnection connection = new xmppconnection(connconfig); try { connection.connect(); log.i("xmppchatdemoactivity", "connected " + connection.gethost()); } catch (xmppexception ex) { log.e("xmppchatdemoactivity", "failed connect " + connection.gethost()); log.e("xmppchatdemoactivity", ex.tostring()); setconnection(null); } try { connection.login(username, password); log.i("xmppchatdemoactivity", "logged in " + connection.getuser()); presence presence = new presence(presence.type.ava...

int - MySql user input restriction -

i new mysql, trying create table store scores ranging 0 5. keep reading constraint check fails, allows me input numbers greater 5. here sample of script create table part2( p2_q1 int(1) check (p2_q1 >= 0 , p2_q1 < 6), //this 1 way i've read p2_q2 int(1) check (p2_q2 >= 0 , p2_q2 < 6), p2_q3 int(1) check (p2_q3 between 0 , 5), //and other way p2_q4 int(1) check (p2_q4 between 0 , 5) ); thanks ahead of time can get! you can define check constraints in mysql has no effect. engine ignores whatever define. may supported in future version of mysql. but instead can define 2 triggers called on every update , insert. insert trigger: delimiter | create trigger `ins_p2` before insert on `part2` each row begin if new.p2_q1 not between 0 , 5 , new.p2_q2 not between 0 , 5 , new.p2_q3 not between 0 , 5 , new.p2_q4 not between 0 , 5 signal sqlstate '45000' set message_text = 'o...