w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Ubuntu/Python- How to call ubuntu commands and 3rd party applications through Python
Take a look at os.path for directory navigation. To execute a shell command use os.system. The example you posted could go something along the lines of: os.chdir(os.path.expanduser('~/Documents/XDF_Thumbnails_Sci')) for file in os.listdir('.'): if os.path.splitext(file)[1] == ".feedme": os.system("~/galfit %s" % file)

Categories : Python

Very slow execution of Matlab code under ubuntu
I had a similar problem at windows, but I believe the solution is same on Ubuntu LTS. So, if you increase the Java Heap Memory of Matlab, the Matlab will consume more memory from your system but it will be faster. To do that go to: File->preferences->General->Java Heap Memory and increase to the maximum. The default value is 128, that is too little.

Categories : Matlab

website on ubuntu suddenly running slow
Have you tried rebooting? in the old days it helped clearing the memory once in a while. another thing making apache slow is the hostnamelookup, perhaps the dns chaching server has issues. as always look at the log files. perhabs there's somewhere a loop (dns or 302 .htaccess)

Categories : Mysql

How to limit download rate of HTTP requests in requests python library?
There are several approaches to rate limiting; one of them is token bucket, for which you can find a recipe here and another one here. Usually you would want to do throttling or rate limiting on socket.send() and socket.recv(). You could play with socket-throttle and see if it does what you need. This is not to be confused with x-ratelimit rate limiting response headers, which are related to a number of requests rather than a download / transfer rate.

Categories : Python

python-requests returning unicode Exception message (or how to set requests locale)
You can try os.strerror, but it would probably return nothing or the same non-English string. This hard-coded English was scraped from here: http://support.microsoft.com/kb/819124 ENGLISH_WINDOWS_SOCKET_MESSAGES = { 10004: "Interrupted function call.", 10013: "Permission denied.", 10014: "Bad address.", 10022: "Invalid argument.", 10024: "Too many open files.", 10035: "Resource temporarily unavailable.", 10036: "Operation now in progress.", 10037: "Operation already in progress.", 10038: "Socket operation on nonsocket.", 10039: "Destination address required.", 10040: "Message too long.", 10041: "Protocol wrong type for socket.", 10042: "Bad protocol option.", 10043: "Protocol not supported.", 10044: "Socket type not supported.",

Categories : Python

Django Requests with Errors Very Slow
The two issues were: require_debug_false filter was inadvertently missing from the mail_admins logging handler: ... 'handlers': { ... 'mail_admins': { 'filters': [''], should have specified: 'filters': ['require_debug_false'], As a result, even with DEBUG=True Django would attempt to send an error email to mail_admins however the settings were only configured to work with the SMTP mail server in a staging or production environment so it was hanging trying to connect to the mail server.

Categories : Django

Looping through users with Instagram API requests is REALLY slow
Doing the requests sequentially will take longer than doing the requests in parallel. You'll want to do concurrent requests to speed this up. Take a look at this answer using curl_multi.

Categories : PHP

Consecutive requests with python Requests.Session() not working
In the lastest version of requests, he sessions object is with Cookie Persistence, look the requests Sessions ojbects docs. So you don't need add the cookie artificialy. Just import requests s=requests.Session() login_data = dict(userName='user', password='pwd') ra=s.post('http://example/checklogin.php', data=login_data) print ra.content print ra.headers ans = dict(answer='5') r=s.post('http://example/level1.php',data=ans) print r.content Just print the cookie to look up wheather you were logged. for cookie in s.cookies: print (cookie.name, cookie.value) And is the example site is yours? If not maybe the site reject the bot/crawler ! And you can change your requests's user-agent as looks likes you are using a browser. For example: import requests s=requests.Session() headers

Categories : Python

Imageresizer seems to add 5 to 6 seconds to all requests and makes debugging very slow
ImageResizer.MvcWebConfig adds a total of 235kb to your project, and takes no actions during startup except reading from the Web.config file. You're seeing 3 minute debugger attach times - that generally indicates a symbol loading problem, and you can fix that in Visual Studio settings. Any NuGet package you install will cause the same behavior - if the package offers source code and/or symbols. I suggest retagging your question as 'nuget' and 'visualstudio'.

Categories : Asp Net Mvc

How should you handle slow requests (image upload from mobile) on Heroku?
Your best option is to upload the images directly to Amazon S3 and then have it ping you with the details of what was uploaded. https://devcenter.heroku.com/articles/s3#file-uploads

Categories : Ruby

ascii codec can't decode byte 0xe3 in position error in Ubuntu/Python, but not on OS X/Python
You haven't given us enough information to be sure, but there's a pretty good chance this is your problem: If some_text is a unicode object, then this line: html1, html2 = html.split(some_text) # this line spits out the error … is calling split on a str, and passing a unicode parameter. Whenever you mix str and unicode in the same call, Python 2.x handles that by automatically calling unicode on the str. So, that's equivalent to: html1, html2 = unicode(html).split(some_text) # this line spits out the error … which is equivalent to: html1, html2 = html.decode(sys.getdefaultencoding()).split(some_text) # this line spits out the error … which will fail if there are any non-ASCII characters in html, exactly as you're seeing. The easy workaround is to explicitly encode some_t

Categories : Python

Requests library crashing on Python 2 and Python 3 with
This means that the server did not send an encoding for the content in the headers, and the chardet library was also not able to determine an encoding for the contents. You in fact deliberately test for the lack of encoding; why try to get decoded text if no encoding is available? You can try to leave the decoding up to the BeautifulSoup parser: if response.encoding is None: soup = bs4.BeautifulSoup(response.content) and there is no need to pass in the encoding to BeautifulSoup, since if .text does not fail, you are using Unicode and BeautifulSoup will ignore the encoding parameter anyway: else: soup = bs4.BeautifulSoup(response.text)

Categories : Python

why can't I connect python to firebird in ubuntu 12.04?
This is untested, but my suspicion is: The error says you cannot connect to 'localhost', which is a network name for the computer you are using. However, you ask Firebird to connect to '/tmp/test.fbd', which is a file system location. Basically, firebird thinks that the you want to connect to the file '/tmp/test.fbd' as if it were a server. Try: con = fdb.connect(host="localhost", database="/tmp/test.fdb", user="fernando", password="root") or con = fdb.connect(dsn="localhost:/tmp/test.fdb", user="fernando", password="root") Assuming of course, that /tmp/fest.fbd is actually on your localhost.

Categories : Python

Ubuntu add directory to Python path
Create a .bash_profile in your home directory. Then, add the line PYTHONPATH=$PYTHONPATH:new_dir EXPORT $PYTHONPATH Or even better: if [ -d "new_dir" ] ; then PYTHONPATH="$PYTHONPATH:new_dir" fi EXPORT $PYTHONPATH The .bash_profile properties are loaded every time you log in. The source command is useful if you don't want to log in again.

Categories : Python

Screen recorder in Ubuntu using python
The way you've written the code, you have to wait for each file to save before you grab the next screenshot. That's where your "very small delay" comes from. You could grab all of the snapshots in memory and then write them at the end: snapshots = [] for i in range(20): b = wx.EmptyBitmap(w, h) m.SelectObject(b) m.Blit(0, 0, w, h, s, 0, 0) m.SelectObject(wx.NullBitmap) snapshots.append(b) for snapshot in snapshots: snapshot.SaveFile('{0:05d}.png'.format(i), wx.BITMAP_TYPE_PNG) But this will use up a lot of memory—maybe enough for the malloc calls (or, worse, swap thrash) to slow you down. Another alternative is to push the write off to a background thread. (Since the work is probably I/O bound, normal Python threads should be fine here.) For example: with concurre

Categories : Python

How to install PyQt on Ubuntu 12.04 with python 2.7?
You did in fact properly install the python bindings for Qt4 when you used: sudo aptitude install python-qt4 You should usually use the Distribution-provided packages - the Ubuntu-provided packages are perfectly adequate for your needs. What's puzzling me is the error you got after installing the Ubuntu package. I just tried this on a Ubuntu 12.04 installation and it worked for me. That suggests to me that your current installation of Ubuntu on your system is broken in some way. You could try completely purging the python-qt4 package and reinstalling it again; sudo apt-get remove --purge python-qt4 If you also issue: sudo apt-get clean ... that will remove any downloaded package files from the system, so that apt will then download the package file again when you issue a sudo a

Categories : Python

Trying to run a python script from ubuntu crontab
I'm not sure what you expect to happen here. The cronjob won't have access to a display where it can display the GUI, so the button will never be displayed, so print_this will never be run FWIW, when I tried to run your code I got an error: File "./t.py", line 4 def __init__(self,parent): ^ IndentationError: expected an indented block Not sure if that's just caused by copy/paste into the page or if it's a real problem with your code.

Categories : Python

What is the correct way to use python Requests
So, I've looked at the documentation and... I think it automatically keeps your session alive for you. Let me know if you have any problems with dying sessions, but assume that Requests will deal with that for you. I may have misinterpreted the docs, but I don't think you need to worry about it. From the documentation: Keep-Alive Excellent news — thanks to urllib3, keep-alive is 100% automatic within a session! Any requests that you make within a session will automatically reuse the appropriate connection! Note that connections are only released back to the pool for reuse once all body data has been read; be sure to either set stream to False or read the content property of the Response object.

Categories : Python

python-requests - can't login
There are lots of options, but I have had success using cookielib instead of trying to "manually" handle the cookies. import urllib2 import cookielib cookiejar = cookielib.CookieJar() cookiejar.clear() urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) # ...etc... Some potentially relevant answers on getting this set up are on SO, including: http://stackoverflow.com/a/5826033/1681480

Categories : Python

Python : Soap using requests
It is indeed possible. Here is an example calling the Weather SOAP Service using plain requests lib: import requests url="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL" #headers = {'content-type': 'application/soap+xml'} headers = {'content-type': 'text/xml'} body = """<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:ns0="http://ws.cdyne.com/WeatherWS/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header/> <ns1:Body><ns0:GetWeatherInformation/></ns1:Body> </SOAP-ENV:Envelope>""" response = requests.post(url,data=body,headers=headers) print

Categories : Python

XML-RPC Python Slow before first request
In Python, due to the GIL, threads doesn't really execute in parallel. If the RPC part is waiting in an active way (loop poling for connection instead of waiting), you most probably will have the behavior you are describing. However, without seeing any code, this is just wild guess.

Categories : Python

python program very slow
It is slow because you are re-reading a file for each loop iteration, and create a new function object. Neither of these two things are dependent on the loop variable; move these out of the loop to only run once. Furthermore, the simple function can be inlined; calling a function is relatively expensive. And don't call ''.join() twice, either. And you are only using lowercase letters to generate the words, so .lower() is redundant: with open('/Users/kyle/Documents/english words.txt') as word_file: english_words = set(word.strip().lower() for word in word_file) for p1 in itertools.combinations('abcdefghijklmnopqrstuvwxyz', 4): word = ''.join(p1) print '{} is {}'.format(word, word in english_words) Since you are generating words of length 4, you could save yourself some memo

Categories : Python

Python ImportError while module is installed [Ubuntu]
/host/Python27/Lib/site-packages is not a default python directory on linux installations as far as I am aware. The normal python installation (and python packages) should be found under /usr/lib or /usr/lib64 depending on your processor architecture. If you want to check where python is searching in addition to these directories you can use a terminal with the following command: echo $PYTHONPATH If the /host/Python27/Lib/site-packages path is not listed, attempt to use the following command and try it again: export PYTHONPATH=$PYTHONPATH:host/Python27/Lib/site-packages If this should work and you do not want to write this in a terminal every time you want to use these packages, simply put it into a file called .bashrc in your home folder (normally /home/<username>).

Categories : Python

starting a python 3.3. script at ubuntu startup
The shebang line #!/usr/bin/python3 should work if sh, bash, etc. is trying to launch your script. It it is being run from another script as python myscript.py you'll have to find that script and get it to launch the script using python3 myscripy.py

Categories : Python

Deploying Python application+dependencies on OSX from Ubuntu
You can use py2exe for Windows Freeze on Linux and as you say py2app for Mac

Categories : Python

How do I install python-ldap in a virtualenv on Ubuntu?
I found this blog post which has the answer: http://blog.mattwoodward.com/2012/10/installing-python-ldap-in-virtualenv-on.html Essentially, you need to ensure you have the necessary development libraries installed: sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev

Categories : Python

Python script on Ubuntu VM can't connect to twitter API
Try creating a https handler and see if that fixes the problem. Change this line: proxy = urllib2.ProxyHandler({'http': 'http://my-proxy-server:80'}) to proxy = urllib2.ProxyHandler({'https': 'http://my-proxy-server:80'}) and see if that works, since the Twitter API you are trying to access is over HTTPS.

Categories : Python

Install lxml on ubuntu 13.04 for python 3.3 Eclipse
Update your PYTHONPATH in Eclipse, go to Preferences > PyDev > Interpreters - Python Then update your paths to lxml package. I suggest you to reload your interpreter (first delete it, and next add it again) it will load all packages and PyDev will recognized lxml

Categories : Python

How do I turn my python program into a service on uBuntu?
You need to write a script in /etc/init.d/ ,in this script ,you need to define how to start and stop the software.here is an example: case "$1" in start) start_software ;; stop) stop_software ;; *) echo "Usage: $0 start|stop" >&2 exit 3 ;; exit 0

Categories : Python

Python Process using only 1.6 GB RAM Ubuntu 32 bit in Numpy Array
A 32-bit OS can only address up to aroung 4gb of ram, while a 64-bit OS can take advantage of a lot more ram (theoretically 16.8 million terabytes). Since your OS is 32-bit, your OS can only take advantage of 4gb, so your other 4gb isn't used. The other 64-bit machine doesn't have the 4gb ram limit, so it can take advantage of all of its installed ram. These limits come from the fact that a 32-bit machine can only store memory address (pointers) of 32-bytes, so there are 2^32 different possible memory locations that the computer can identify. Similarly, a 64-bit machine can identify 2^64 different possible memory locations, so it can address 2^64 different bytes.

Categories : Python

ubuntu ec2 - run python script at startup with arguments
Your /etc/init.d/script_name is missing the plumbing that update-rc.d and so on use, and won't properly handle stop, start, and other init-variety commands, so... For initial experimentation, take advantage of the /etc/init.d/rc.local script (which should be linked to by default from /etc/rc2/S99rc.local). The gets you out of having to worry about the init.d conventions and just add things to /etc/rc.local before the exit 0 at its end. Additionally, that ~ isn't going to be defined, you'll need to use a full pathname - and furthermore the script will run as root. We'll address how to avoid this if desired in a bit. In any of these, you'll need to replace "whoeveryouare" with something more useful. Also be warned that you may need to prefix the python command with a su command and som

Categories : Python

Is there a python module for managing interfaces on Ubuntu?
Why is there any need for a Python module??? All can be done from the command line! E.g. take a look at:https://help.ubuntu.com/10.04/serverguide/network-configuration.html Get the commands needed and execute them from Python.

Categories : Python

Python Multiprocess using Pool fails on AWS Ubuntu
The MemoryError means you're running out of system-wide virtual memory. How much virtual memory you have is an abstract thing, based on the actual physical RAM plus swapfile size plus stuff that's paged into memory from other files and stuff that isn't paged anywhere because the OS is being clever and so on. According to your comments, each process averages 0.75GB of real memory, and 4GB of virtual memory. So, your total VM usage is 32GB. One common reason for this is that each process might peak at 4GB, but spend almost all of its time using a lot less than that. Python rarely releases memory to the OS; it'll just get paged out. Anyway, 6GB of real memory is no problem on an 8GB Mac or a 7GB c1.xlarge instance. And 32GB of VM is no problem on a Mac. A typical OS X system has virtually

Categories : Python

How to log in to Google with Python Requests module?
I think you actually get more interesting data by grabbing the raw JSON that it uses to build the graphs. It includes the related headlines that don't come with the CSV download. This works for a few queries (5?) before you reach the quota. import re import requests _GOOGLE_TRENDS_URL = 'http://www.google.com/trends/trendsReport?hl=en-US&content=1&q=%s&hl=en-US&content=1' term = 'foo' response = requests.get(_GOOGLE_TRENDS_URL % term) if response.status_code == requests.codes.ok: data_line = [l for l in response.content.splitlines() if 'var chartData' in l][0] chart_data = re.sub(r'.*var chartData = (.*?);.*', r'1', data_line) # Fix for date representation chart_data = re.sub(r'new Date((d+), (d+), (d+))', r'"1-2-3"', chart_data) data = json.loads(

Categories : Python

How to get the raw content of a response in requests with Python?
If you are using a requests.get call to obtain your HTTP response, you can use the raw attribute of the response. Here is the code from the requests docs. >>> r = requests.get('https://github.com/timeline.json', stream=True) >>> r.raw <requests.packages.urllib3.response.HTTPResponse object at 0x101194810> >>> r.raw.read(10) 'x1fx8bx08x00x00x00x00x00x00x03'

Categories : Python

How does python know that you need to interface the requests module through api.py?
See here: https://github.com/kennethreitz/requests/blob/master/requests/__init__.py E.g. if 'requests' is a directory, which has __init__.py, Python executes this file each time it sees from requests import ... or import requests. See more in Modues.

Categories : Python

How to get response SSL certificate from requests in python?
This, although not pretty at all, works: import requests req = requests.get('https://httpbin.org') pool = req.connection.poolmanager.connection_from_url('https://httpbin.org') conn = pool.pool.get() # get() removes it from the pool, so put it back in pool.pool.put(conn) print(conn.sock.getpeercert())

Categories : Python

How to loop through API call with requests in python
I think you want to do something like this: for x in coords: loc={'?contains' : x , '&sets' : 'a_parameter'} ... This references the x variable, not the string 'x'.

Categories : Python

Posting to CloudApp API (AWS) with Python Requests
After several days, I finally figured out the (simple) problem. The CloudApp API requires a "GET" request to the "Location" header in Amazon's response. Pycloudapp was working correctly because it properly authenticated the GET response with return json.load(self.upload_auth_opener.open(request)). I'm not sure why I was able to post correctly using Postman without any authentication -- somehow it was properly following the GET without credentials, even though the CloudApp API specifies that following the redirect requires authentication. I was unable to follow the redirect properly with Requests because I was posting unauthenticated values (if I continued the Session() with s.post, the auth headers throw an error because Amazon doesn't expect them), and therefore the subsequent GET was

Categories : Python

HTML 501 error using Python Requests
I looked through the site and it appears that you are using a GET HTTP method to retrieve the data when what you actually need is a POST. Typically an HTTP 501 is sent across as a response to the client, when the web server does not understand the HTTP verb sent across by the client within the request. Try changing the code: r = requests.get('https://venta.renfe.com/vol/inicioCompra.do', data=payload, cookies=cookies, headers=headers) to something like r = requests.post('https://venta.renfe.com/vol/inicioCompra.do', data=payload, cookies=cookies, headers=headers) Note : I have not used Requests, hence you may want to double check the function call parameters. For a quick reference see this link. Hope this helps - and here is a dump of my header as visible in Chrome. Observe that y

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.