python-3.4

smtplib.SMTP starttls fails with tlsv1 alert decode error

核能气质少年 提交于 2019-12-07 05:21:44
问题 I encountered the following perculiar behaviour today. The following code works on Python 3.3: smtp = smtplib.SMTP() smtp.connect(host="smtp.gmail.com", port=587) smtp.ehlo() smtp.starttls() In Pyhton 3.4 the above code doesn't work, instead the following error is encountered: File "smtp_test.py", line 10, in <module> smtp.starttls() File "/usr/lib/python3.4/smtplib.py", line 676, in starttls server_hostname=server_hostname) File "/usr/lib/python3.4/ssl.py", line 344, in wrap_socket _context

Object that raises exception when used in any way

纵然是瞬间 提交于 2019-12-07 04:06:55
问题 I need to create an object that would raise a custom exception, UnusableObjectError , when it is used in any way (creating it should not create an exception though). a = UnusableClass() # No error b = UnusableClass() # No error a == 4 # Raises UnusableObjectError 'x' in a # Raises UnusableObjectError for i in a: # Raises UnusableObjectError print(i) # ..and so on I came up with the code below which seems to behave as expected. class UnusableObjectError(Exception): pass CLASSES_WITH_MAGIC

Preferred block size when reading/writing big binary files

折月煮酒 提交于 2019-12-07 02:32:44
问题 I need to read and write huge binary files. Is there a preferred or even optimal number of bytes (what I call BLOCK_SIZE ) I should read() at a time? One byte is certainly too little, and I do not think reading 4 GB into the RAM is a good idea either - is there a 'best' block size? or does that even depend on the file-system (I'm on ext4)? What do I need to consider? Python's open() even provides a buffering argument. Would I need to tweak that as well? This is sample code that just joins the

Python relative import with more than two dots

有些话、适合烂在心里 提交于 2019-12-07 01:10:12
问题 Is it ok to use a module referencing with more than two dots in a path? Like in this example: # Project structure: # sound # __init__.py # codecs # __init__.py # echo # __init__.py # nix # __init__.py # way1.py # way2.py # way2.py source code from .way1 import echo_way1 from ...codecs import cool_codec # Do something with echo_way1 and cool_codec. UPD: Changed the example. And I know, this will work in a practice. But is it a common method of importing or not? 回答1: From PEP8: Absolute imports

How to install xmlrpclib in python 3.4?

╄→гoц情女王★ 提交于 2019-12-06 19:12:26
问题 When I am trying to install xmlrpclib, I am getting following error in python version 3.4 Downloading/unpacking xmlrpclib Could not find any downloads that satisfy the requirement xmlrpclib Some externally hosted files were ignored (use --allow-external xmlrpclib to allow). Cleaning up... No distributions at all found for xmlrpclib Storing debug log for failure in /home/shiva/.pip/pip.log How to install xmlrpclib in python 3.4 ? 回答1: xmlrpclib is part of the standard library in Python 2.x. It

Subclass `pathlib.Path` fails

岁酱吖の 提交于 2019-12-06 16:59:03
问题 I would like to enhance the class pathlib.Path but the simple example above dose not work. from pathlib import Path class PPath(Path): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) test = PPath("dir", "test.txt") Here is the error message I have. Traceback (most recent call last): File "/Users/projetmbc/test.py", line 14, in <module> test = PPath("dir", "test.txt") File "/anaconda/lib/python3.4/pathlib.py", line 907, in __new__ self = cls._from_parts(args, init=False)

Python, save as mht

半腔热情 提交于 2019-12-06 15:34:51
I can bring up a web page, no problem. I can save the webpage...as html, no problem. I need to save the webpage as mht so I can can get all the html that gets hidden without saving as mht. In researching I'm coming up with absolutely nothing as to how to save as mht using python. Like I said above I can try to save it as a mht file, using the standard coded for saving as html but that simply doesn't work...not surprised it doesn't work either, but it was worth a shot. url = 'https://www.thewebsite.com' html = urllib.request.urlopen(url).read() m = open('websitetest.mht', 'w') m.write(str(html)

How to install PyQt5 wtih Python3.4 and SIP 4.19.1?

流过昼夜 提交于 2019-12-06 13:16:10
I need to use Python3.4 which is installed on my XP machines. Now I am trying to install PyQt5 in Win10 with Python34. However, when I run pip3 install PyQt5 I get: Could not find any downloads that satisfy the requirement SIP>=4.19.1 Then I tried to install SIP froom PyPI download site for SIP but it says Python version is min. 3.5. Even the oldest version 4.18 is for Python3.5. Is there a way to use PyQt5 with Python34? Or can I run the app in XP if I use Python36 for writing and pack it with pyinstaller in one executable? 来源: https://stackoverflow.com/questions/50483708/how-to-install-pyqt5

“TypeError: Can't convert 'NoneType' object to str implicitly” when var should have a value

巧了我就是萌 提交于 2019-12-06 13:11:39
import sys from tkinter import * def print(): print("Encoded " + message + " with " + offset) gui = Tk() gui.title("Caesar Cypher Encoder") Button(gui, text="Encode", command=encode).grid(row = 2, column = 2) Label(gui, text = "Message").grid(row = 1, column =0) Label(gui, text = "Offset").grid(row = 1, column =1) message = Entry(gui).grid(row=2, column=0) offset = Scale(gui, from_=0, to=25).grid(row=2, column=1) mainloop( ) When i run this code with an input in both the input box and a value on the slider - it comes up with the error >>>Exception in Tkinter callback Traceback (most recent

How do you change the value of one attribute by changing the value of another? (dependent attributes)

时间秒杀一切 提交于 2019-12-06 09:59:00
So I've recently dived into OOP, and so far everything is going smooth. Whilst I have no issues per se, there's an amazing feature which I hope exists, though I cannot find any documentation on said feature. When assigning attributes to objects, I often find that I have to change attribues that are dependent upon others, say, light and darkness. Here's an example: class shade: def __init__(self, light): self.light=light self.darkness=100-light def __str__(self): return (str(self.light) + ',' + str(self.darkness)) >>> shade1=shade(30,70) >>> shade1.light 30 >>> shade1.darkness 70 Now, while