问题描述
根据下面的代码,我将拉取请求编号保存在一个文本文件中,我想将它们上传到我的代码中的 url,但我收到了标题中提到的错误.
According to this code below, I saved the pull request number in a text file and I want to upload them to the url that is in my code but I got the error mentioned in the title.
import urllib2
import json
import httplib
def event_spider(org,repo):
try:
nbPrequest_reopened=0 #number of pull requests reopened
pages=1
while pages<=3:
headers={'User-Agent':'Mozilla/5.0(X11;Linux i686)',
'Authorization':'token 516ed78e0521c6b25d9726ad51fa63841d019936',}
read_file=open('C:\Python27\pullRequest_number.txt','r+')
rf=read_file.readlines()
for number in rf:
url_event=('https://api.github.com/repos/'+ org +'/'+ repo + '/issues/'+ str(number) +'/events?per_page=99&state=all&page='+str(pages))
event_Request=urllib2.Request(url_event,headers=headers)
eventObject=urllib2.urlopen(event_Request)
eventData=json.load(eventObject)
for element in eventData:
if element['event']=='reopened':
nbPrequest_reopened+=1
#print url_event
pages+=1
except httplib.BadStatusLine:
pass
print 'The number of pull request reopened is %s ' %(nbPrequest_reopened)
if __name__=='__main__':
event_spider('rails','rails')
回溯(最近一次调用最后一次):
Traceback (most recent call last):
File "C:/Users/ABDILLAH/PycharmProjects/Pandas_data_analysis/event_spider.py", line 27, in <module>
event_spider('rails','rails')
File "C:/Users/ABDILLAH/PycharmProjects/Pandas_data_analysis/event_spider.py", line 16, in event_spider
eventObject=urllib2.urlopen(event_Request)
File "C:\Python27\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 427, in open
req = meth(req)
File "C:\Python27\lib\urllib2.py", line 1126, in do_request_
raise URLError('no host given')
urllib2.URLError: <urlopen error no host given>
有人可以帮我解决这个问题吗?谢谢.
Can someone help me to solve this problem?Thanks.
推荐答案
有一个简单的解决方法.我取自 https://github.com/rg3/youtube-dl/pull/11892/files(youtube-dl 项目也有这个问题).
There's an easy fix for that.I took it from https://github.com/rg3/youtube-dl/pull/11892/files (youtube-dl project had this problem too).
pytube 中的修复将是这样(我将尝试在今天之前上传拉取请求):在 api.py 文件中,您应该更改 2 行代码.首先,在函数 _get_cipher 下,您应该更改行:
Fix in pytube will be like that (I'll try to upload a pull request by today):In api.py file you should change 2 code lines.First, under the function _get_cipher you should change the line:
reg_exp = re.compile(r'\.sig\|\|([a-zA-Z0-9$]+)\(')
到:
reg_exp = re.compile(r'"signature",\s?([a-zA-Z0-9$]+)\(')
其次,在 from_url 函数下,您应该更改这一行:
Second, under the function from_url you should change this line:
js_url = "http:" + video_data.get("assets", {}).get("js")
到这个代码:
js_url = '' js_partial_url = video_data.get("assets", {}).get("js")
if js_partial_url.startswith('//'):
js_url = 'http:' + js_partial_url
elif js_partial_url.startswith('/'):
js_url = 'https://youtube.com' + js_partial_url
这篇关于urllib2.URLError: urlopen 错误没有给出主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!