在封装读取剪贴板的时候,执行测试代码时遇到个错误:

pywintypes.error: (1418, 'GetClipboardData', '\xcf\xdf\xb3\xcc\xc3\xbb\xd3\xd0\xb4\xf2\xbf\xaa\xb5\x

代码:

#encoding=utf-8
import win32clipboard as w
import win32con
import time
class Clipboard(object):
#模拟Windows设置剪贴板 #读取剪贴板
@staticmethod
def getText():
#打开剪贴板
w.OpenClipboard()
#获取剪贴板中的数据
content=w.GetClipboardData(win32con.CF_TEXT)
#关闭剪贴板
w.CloseClipboard()
#返回剪贴板数据
return content #设置剪贴板内容
@staticmethod
def setText(aString):
#打开剪贴板
w.OpenClipboard()
#清空剪贴板
w.EmptyClipboard()
#将数据aString写入剪贴板
w.SetClipboardData(win32con.CF_UNICODETEXT,aString)
#关闭剪贴板
w.CloseClipboard()
if __name__=='__main__':

    Clipboard.setText(u'hey buddy!')
print Clipboard.getText()

然后在网上查,是因为设置了剪贴板内容之后,马上就读取剪贴板内容的话,可能这时候剪贴板的内容还没设置好,读取不到内容就会报错,

需要在设置剪贴板之后等几秒钟。

测试改成:

if __name__=='__main__':

    Clipboard.setText(u'hey buddy!')
#time.sleep(3)
print Clipboard.getText()

结果:

C:\Python27\python.exe D:/test/hybrid_version2/util/keyboard.py
hey buddy!

Process finished with exit code 0

												

python读取剪贴板报错 pywintypes.error: (1418, 'GetClipboardData', '\xcf\xdf\xb3\xcc\xc3\xbb\xd3\xd0\xb4\xf2\xbf\xaa\xb5\x的更多相关文章

  1. python操作剪贴板错误提示:pywintypes.error: (1418, 'GetClipboardData',线程没有打开的剪贴板)

    问题现象:通过打断点,一步步调试可以正常复制和粘贴剪贴板数据.但是直接运行会报错pywintypes.error: (1418, 'GetClipboardData',线程没有打开的剪贴板) 问题原因 ...

  2. python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multib

    python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multib ...

  3. 【python】python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte sequence

    python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte ...

  4. python 读取文件时报错UnicodeDecodeError

    python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multib ...

  5. python读取文件报错:pandas.errors.ParserError: iterator should return strings, not bytes (did you open the file in text mode?)

    python 读取csv文件报错问题 import csv with open('E:/Selenium2script/DDT模块/test.csv','rb') as f: readers = cs ...

  6. python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multibyte sequence

    python读取文件时提示"UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal m ...

  7. python 读取文件时报错: UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 127: illegal multibyte sequence

    UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 127: illegal multibyte sequence p ...

  8. 【Python】Python读取文件报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0x99 in position 20: illegal multibyte sequence

    环境描述 text.txt 今天的天气不错 是个皻的选择 读取文件的代码 #!/usr/bin/python #-*- coding:UTF-8 -*- f = open(r'D:\Python\Py ...

  9. Python读取xml报错解析--ExpatError: not well-formed (invalid token)

    xml文件内容如代码所示存入的名字为login.xml: <?xml version="1.0" encoding="utf-8"?> <in ...

随机推荐

  1. intellij idea如何快速格式化代码

    选中代码,一键格式化代碼: Ctrl+Alt+L

  2. LCA最近公共祖先(least common ancestors)

    #include"stdio.h" #include"string.h" #include"iostream" #include" ...

  3. table-layout:fixed 布局注意事项

    table-layout:auto 是表格布局中的默认值,采用浏览器自动表格布局算法,但是缺点会很明显 给td指定的width不一定生效,td的width会自动调整 text-overflow: el ...

  4. eclipse配置Js环境spket

    网上下载spket-1.6.16.jar破解版(目前最新版本) 1.如果你的JDK在1.6以上,可以直接双击spket-1.6.16.jar运行安装. 其它,使用命令行方式.(注意:自己切换命令行到s ...

  5. createrepo local http yum

    https://www.jianshu.com/p/59ca879584a1   repodata作为软件的仓库,其目录下有四个必要文件:filelists.xml.[gz],other.xml.[g ...

  6. android speakerphone/

    http://www.cnblogs.com/innost/archive/2011/01/22/1942149.html http://blog.sina.com.cn/s/blog_5418969 ...

  7. 【pip uninstall 无法卸载】Not uninstalling numpy at /usr/lib/python2.7/dist-packages, outside environment /usr

    想卸载python的库numpy,执行pip uninstall gunicorn,报错如下: Not uninstalling numpy at /usr/lib/python2.7/dist-pa ...

  8. Zero-Copy技术

    概述 考虑这样一种常用的情形:你需要将静态内容(类似图片.文件)展示给用户.那么这个情形就意味着你需要先将静态内容从磁盘中拷贝出来放到一个内存buf中,然后将这个buf通过socket传输给用户,进而 ...

  9. sass,less的安装及sass的教程

    装scss(window) 首相安装ruby http://www.sasschina.com/install/ scss转译css http://www.cnblogs.com/52css/arch ...

  10. requests库的get请求,带有cookies

    (一)如何带cookies请求 方法一:headers中带cookies #coding:utf-8 import requests import re # 构建url url = 'http://w ...