Daily Archives

Articles indexed Wednesday June 2 2010

Page 5/120 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Python form POST using urllib2 (also question on saving/using cookies)

    - by morpheous
    I am trying to write a function to post form data and save returned cookie info in a file so that the next time the page is visited, the cookie information is sent to the server (i.e. normal browser behavior). I wrote this relatively easily in C++ using curlib, but have spent almost an entire day trying to write this in Python, using urllib2 - and still no success. This is what I have so far: import urllib, urllib2 import logging # the path and filename to save your cookies in COOKIEFILE = 'cookies.lwp' cj = None ClientCookie = None cookielib = None logger = logging.getLogger(__name__) # Let's see if cookielib is available try: import cookielib except ImportError: logger.debug('importing cookielib failed. Trying ClientCookie') try: import ClientCookie except ImportError: logger.debug('ClientCookie isn\'t available either') urlopen = urllib2.urlopen Request = urllib2.Request else: logger.debug('imported ClientCookie succesfully') urlopen = ClientCookie.urlopen Request = ClientCookie.Request cj = ClientCookie.LWPCookieJar() else: logger.debug('Successfully imported cookielib') urlopen = urllib2.urlopen Request = urllib2.Request # This is a subclass of FileCookieJar # that has useful load and save methods cj = cookielib.LWPCookieJar() login_params = {'name': 'anon', 'password': 'pass' } def login(theurl, login_params): init_cookies(); data = urllib.urlencode(login_params) txheaders = {'User-agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'} try: # create a request object req = Request(theurl, data, txheaders) # and open it to return a handle on the url handle = urlopen(req) except IOError, e: log.debug('Failed to open "%s".' % theurl) if hasattr(e, 'code'): log.debug('Failed with error code - %s.' % e.code) elif hasattr(e, 'reason'): log.debug("The error object has the following 'reason' attribute :"+e.reason) sys.exit() else: if cj is None: log.debug('We don\'t have a cookie library available - sorry.') else: print 'These are the cookies we have received so far :' for index, cookie in enumerate(cj): print index, ' : ', cookie # save the cookies again cj.save(COOKIEFILE) #return the data return handle.read() # FIXME: I need to fix this so that it takes into account any cookie data we may have stored def get_page(*args, **query): if len(args) != 1: raise ValueError( "post_page() takes exactly 1 argument (%d given)" % len(args) ) url = args[0] query = urllib.urlencode(list(query.iteritems())) if not url.endswith('/') and query: url += '/' if query: url += "?" + query resource = urllib.urlopen(url) logger.debug('GET url "%s" => "%s", code %d' % (url, resource.url, resource.code)) return resource.read() When I attempt to log in, I pass the correct username and pwd,. yet the login fails, and no cookie data is saved. My two questions are: can anyone see whats wrong with the login() function, and how may I fix it? how may I modify the get_page() function to make use of any cookie info I have saved ?

    Read the article

  • Java interface design

    - by Nayn
    Hi, I had an interface initially as below. public interface testMe { public Set<String> doSomething(); } public class A implements testMe { public Set<String> doSomething() { return // Set<String> } } I had similar classes implementing testMe. Now I have to add one more class which returns Set<Some Object> public class X implements testMe() { public Set<Some OBject> doSomething() { } } How could i add this mehtod in the interface without breaking existing classes? Thanks Nayn

    Read the article

  • mysql query - blog posts and comments with limit

    - by Lemon
    Hi, I have 2 tables: comments and posts and I'd like to display a list of 15 posts and maximum 2 most recent comments under each blog post the database scheme looks like this posts_table: post_id, post_txt, post_timestamp comments_table: post_id, comment_txt, comment_timestamp how the mysql query should look like to select 15 posts and related comments (max 2 most recent ones per post) ??? thanks, Leo

    Read the article

  • chrome & safari css/javascript issue ajax load function

    - by user295292
    Do I load the scripts/css again in other.html when I'm using the .load('other.html') from index.html? index.html = jQuery & cycle plugin, other.html = jQuery & cycle plugin FF & IE load the other.html fine when they're both (script/css) in the index.html. But Chrome & Safari act as if it can't read the script and css.

    Read the article

  • chrome-like status bar in qt

    - by hasen j
    I'm not big on creating GUI's, and generally my philosophy is: I don't create them, or I make them as simple as possible (and convince myself that it's better for usability :) For my current project, I'm using Qt from Python (PyQt), and I want to start adding some GUI elements without cluttering the interface. My idea is to create these elements as sort of floating-shaped-widgets that only appear when necessary; pretty much like the status bar (and find bar) in chrome. Is there any standard api that enables creating this kind of interface?

    Read the article

  • MySQL “filegroup”??

    - by Xaitec
    Coming for using Sql Server where there are file-groups, i was wondering if there is (i'm sure there is) something similar in MySQL. After all the database cant be limited to just one hard drive( if using windows that is). I've tried to search but its hard to find the something that you don't know the name of!.

    Read the article

  • Apache HttpClient Digest authentication

    - by Milan Jovic
    Hi, Basically what I need to do is to perform digest authentication. First thing I tried is the official example available here. But when I try to execute it(with some small changes, Post instead of the the Get method) I get a org.apache.http.auth.MalformedChallengeException: missing nonce in challange at org.apache.http.impl.auth.DigestScheme.processChallenge(DigestScheme.java:132) When this failed I tried using: DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(new AuthScope(null, -1, null), new UsernamePasswordCredentials("<username>", "<password>")); HttpPost post = new HttpPost(URI.create("http://<someaddress>")); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("domain", "<username>")); post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); DigestScheme digestAuth = new DigestScheme(); digestAuth.overrideParamter("algorithm", "MD5"); digestAuth.overrideParamter("realm", "http://<someaddress>"); digestAuth.overrideParamter("nonce", Long.toString(new Random().nextLong(), 36)); digestAuth.overrideParamter("qop", "auth"); digestAuth.overrideParamter("nc", "0"); digestAuth.overrideParamter("cnonce", DigestScheme.createCnonce()); Header auth = digestAuth.authenticate(new UsernamePasswordCredentials("<username>", "<password>"), post); System.out.println(auth.getName()); System.out.println(auth.getValue()); post.setHeader(auth); HttpResponse ret = client.execute(post); ByteArrayOutputStream v2 = new ByteArrayOutputStream(); ret.getEntity().writeTo(v2); System.out.println("----------------------------------------"); System.out.println(v2.toString()); System.out.println("----------------------------------------"); System.out.println(ret.getStatusLine().getReasonPhrase()); System.out.println(ret.getStatusLine().getStatusCode()); At first I have only overridden "realm" and "nonce" DigestScheme parameters. But it turned out that PHP script running on the server requires all other params, but no matter if I specify them or not DigestScheme doesn't generate them when I call its authenticate() method. I've been struggling with this for two days, and no luck. Based on everything I think that the cause of the problem is the PHP script. It looks to me that it doesn't send a challenge when app tries to access it unauthorized. Any ideas anyone?

    Read the article

  • Problem with using malloc in link lists (urgent ! help please)

    - by Abhinav
    I've been working on this program for five months now. Its a real time application of a sensor network. I create several link lists during the life of the program and Im using malloc for creating a new node in the link. What happens is that the program suddenly stops or goes crazy and restarts. Im using AVR and the microcontroller is ATMEGA 1281. After a lot of debugging I figured out that that the malloc is causing the problem. I do not free the memory after exiting the function that creates a new link so Im guessing that this is eventually causing the heap memory to overflow or something like that. Now if I use the free() function to deallocate the memory at the end of the function using malloc, the program just gets stuck when the control reaches free(). Is this because the memory becomes too clustered after calling free() ? I also create reference tables for example if 'head' is a new link list and I create another list called current and make it equal to head. table *head; table *current = head; After the end of the function if I use free free(current); current = NULL: Then the program gets stuck here. I dont know what to do. What am I doing wrong? Is there a way to increase the size of the heap memory Please help...

    Read the article

  • What Kind of Knowledge is Necessary For a Permon Who Does Not Have IT Background? [closed]

    - by skyflyer
    One of my colleagues joined our company, which by the way is a internet company, months ago as an on-line marketing specialist. He majored English in his college and has never deeply touched IT before. He says that to be a good on-line marketing specialist he needs to lean some basic IT skills in order to deliver superb work. According to him, things like Search Engine Optimization, monitoring competitors' web sites, design some functionality on web site and so on require IT entree-level knowledge. And he asks me what kind knowledge is helpful for him to do his job. I am stunted by his question. It is easy enough to answer, things like HTML, CSS, even Photo-shop are required in some job descriptions. Also, I believe some basic understanding of dynamic web site, static web site is helpful to him. On the other hand, as a techie I still feel my answer is awkward. What is your opinion on this? Always lot of thanks to you guys on SO.

    Read the article

  • Convert CString to string (VC6)

    - by Yan Cheng CHEOK
    I want to convert CString to string. (Yup. I know what am I doing. I know the returned string will be incorrect, if CString value range is outside ANSI, but That's Is OK!) The following code will work under VC2008. std::string Utils::CString2String(const CString& cString) { // Convert a TCHAR string to a LPCSTR CT2CA pszConvertedAnsiString (cString); // construct a std::string using the LPCSTR input std::string strStd (pszConvertedAnsiString); return strStd; } But VC6 doesn't have CT2CA macro. How I can make the code to work as well in both VC6 and VC2008?

    Read the article

  • essential reading for php coding (including databases)?

    - by tombull89
    Hello. I'm more of a SU and SF but now I'm after some help from the SO community. I'm dabbling in a bit of php coding with databases and am getting a bit stuck with relationships and the like. Can anybody reccomend some books, online or real, that would be a good start for someone new(ish) to php and mysql databases? Cheers!

    Read the article

  • What can I read from the iPad Camera Connection Kit?

    - by HELVETICADE
    I'm building a small controller device that I'd like to partner with a computer. I've settled on using OSC out from my custom built hardware and am pretty satisfied with what I can get from WOscLib. Two goals I'd like to achieve are portability and a very ratio between battery:computing power, and this has lured me towards using iPhoneOS to accomplish my goals. I think the iPad would suit my needs perfectly, except that using wifi to broadcast OSC out from my device requires a third device and would destroy the goal of portability, whilst also introducing potential latency and stability headaches. My question is pretty simple: Can I push my OSC-out FROM my controller TO an iPad via USB and the Camera Connection Kit? If I could accomplish this, the two major goals of my project would be fulfilled very nicely. This seems like it should be a simple little question, but researching this obsessively over the past few weeks has left me more almost more uncertain than if I had done no research at all. I'd really like some more confidence before I go down this route, and it seems like it should be possible. Any insight would be very, very appreciated.

    Read the article

  • .NET generic class instance - passing a variable data type

    - by FerretallicA
    As the title suggests, I'm tyring to pass a variable data type to a template class. Something like this: frmExample = New LookupForm(Of Models.MyClass) 'Works fine Dim SelectedType As Type = InstanceOfMyClass.GetType() 'Works fine frmExample = New LookupForm(Of SelectedType) 'Ba-bow! frmExample = New LookupForm(Of InstanceOfMyClass.GetType()) 'Ba-bow! LookupForm<Models.MyClass> frmExample; Type SelectedType = InstanceOfMyClass.GetType(); frmExample = new LookupForm<SelectedType.GetType()>(); //Ba-bow frmExample = new LookupForm<(Type)SelectedType>(); //Ba-bow I'm assuming it's something to do with the template being processed at compile time but even if I'm off the mark there, it wouldn't solve my problem anyway. I can't find any relevant information on using Reflection to instance template classes either. (How) can I create an instance of a dynamically typed repository at runtime?

    Read the article

  • Java & android: Help linking an item in a listView to its correct view, but not the way i know of.

    - by Capsud
    Hi, i'm developing an android app, and what i have is a String array of restaurants in one class... static final String[] AtoZ = new String[] { "Ananda", "Brambles Cafe", "Brannigans", "Buona Sera", "Cafe Mao", "Cafe Mimo", "Dante", "Eddie Rockets", "Frango's World Cuisine", "Nando's", "Overends Restaurant @ Airfield House", "Pizza Hut", "Roly Saul", "Siam Thai","Smokey Joes","Sohag Tandoori", "TGI Friday","The Rockfield Lounge", "Winters Bar", "Al Boschetto","Baan Thai", "Bella Cuba", "Bellamys","Bianconis","Canal Bank Cafe", "Canalettos Restaurant","Chandni Restaurant", "Chill Out Cafe", "Crowes", "Da Vincenzo", "Druids", "Dylan", "Epic Restaurant", "Jewel in the Crown", "Juniors", "Kanum Thai","Kites", "Koishi","Maia Restaurant", "Mangetu Restaurant", "Millers Pizza Kitchens", "O'Connells Restaurant", "Ocras Restaurant", "Orchid Szechuan Restaurant", "Roly's Bistro", "Ryans Beggars Bush", }; i have created a view for each of these restaurants aswell in my layouts folder. so this array is going to be displayed in a listView in my android app. What i want to know is what is the quickest way of linking the item clicked to its correct view, without having to type out each position in the array and have a serious of if statements which would take a year with this! i dont want to be doing something like this if(position == 1){ setContentView(R.layout.bentleys); as it would take a year doing that for each one... Please help. thanks alot.

    Read the article

  • How to insert a blank line above my copyright text inside the comment lines in intelliJ IDEA?

    - by tim_wonil
    I'm using intelliJ IDEA 9. It has a function to make a copyright profile and apply to all files I create. What I'm trying to do is to format the copyright comment right. Suppose I have a copyright text as this: Copyright (c) 2010 my.company. All rights reserved. I wish it to be inserted in files automatically as following: //////////////////////////////////////////////////////////////////////////////// // // Copyright (c) 2010 my.company. All rights reserved. // //////////////////////////////////////////////////////////////////////////////// But when I enter the line "Copyright (c) 2010 my.company. All rights reserved." in the copyright profile (without quotes) and configure the formatting to use line comment and borders, and so on, I can only make it to display as below: //////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2010 my.company. All rights reserved. //////////////////////////////////////////////////////////////////////////////// Even when I put the copyright text with blank line above and below to the template, as following, it still comes out like above. Copyright (c) 2010 my.company. All rights reserved. It seems to ignore blank lines in the copyright template. Is there any way to configure it so the copyright text will have blank lines above and below within the comments?

    Read the article

  • Multidimensional vectors in scheme?

    - by incrediman
    I earlier asked a question about arrays in scheme (turns out they're called vectors but are basically otherwise the same as you'd expect). Is there an easy way to do multidimensional arrays vectors in PLT Scheme though? For my purposes I'd like to have a procedure called make-multid-vector or something. By the way if this doesn't already exist, I don't need a full code example of how to implement it. If I have to roll this myself I'd appreciate some general direction though. The way I'd probably do it is to just iterate through each element of the currently highest dimension of the vector to add another dimension, but I can see that being a bit ugly using scheme's recursive setup. Also, this seems like something I should have been able to find myself so please know that I did actually google it and nothing came up.

    Read the article

  • Store and retrieve html from sql server 2008 and display using ASP.NET MVC?

    - by VJ
    Hi all I am trying to store html and hyperlinks in my sql server 2008 database. I want to also be able to display the hyperlinks and render the html accordingly. I am trying to do this in ASP.NET MVC so I tried using HTTPUtility.HtmlEncode() method but didnt really store it thw way I wanted. So can anyone please guide me through the steps i need to take to achieve this.

    Read the article

  • ?ERP???????????????????

    - by toshiyuki.sakuramoto
    ???????????????????????????????ERP?????14??? ??6?1???????? ??????100%? ??????2????3??????????????????????????? ????????21:40?????????????????????????22????????????????????????????????????????? ?????????????????????????????????????? ???????????????????????????????????????????????? ???????????????????????? ??????????????????????? ????????!????!? ?????????? ?ERP??????????????????? ?2???????????4???????????????????? ?IFRS?ERP??????ERP?EPM?ERP···????????? ????????????????????? ??? ?ERP??????????????????????? ?Oracle???PR?????????????!? ????????? ????????????????????????????????ERP???????????????????????????????????????????? ????????????????????????????????????????

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >